Uređivati

Podijeli putem


Query schema definitions and detect changes

This sample shows how to retrieve and detect changes in table definitions by using the RetrieveMetadataChangeRequest method. You can view the sample at PowerApps-Samples/dataverse/orgsvc/C#-NETCore/Schema/RetrieveMetadataChanges/.

For more information about the functionality, see:

How to run this sample

See the instructions in Schema samples instructions.

Demonstrates

This sample shows how to retrieve schema definitions for a specific set of column definitions and save them in memory to represent a cache.

Then, it creates a new column, retrieves the data for only that new column, and adds it to the cache.

Next, it deletes the column, retrieves data about deleted items, and uses that data to remove the deleted column definition from the cache.

This sample has six sections:

Define query

Define a query by using EntityQueryExpression that returns all the Picklist choice columns from the contact table.

Initialize cache

  1. Create an instance of RetrieveMetadataChangesRequest with the Query parameter set to the query.
  2. Send the request by using IOrganizationService.Execute.
  3. Cache the RetrieveMetadataChangesResponse.EntityMetadata value.
  4. Save the RetrieveMetadataChangesResponse.ServerVersionStamp value for use in the next request.
  5. Write a list of all the current columns in the cache.

Add choice column

Create a new choice column by creating a new PicklistAttributeMetadata instance in the contact table attributes.

Detect added column

  1. Create a new instance of RetrieveMetadataChangesRequest and set the Query parameter to the original query.
  2. Set the RetrieveMetadataChangesRequest.ClientVersionStamp with the value previously returned from the first request.
  3. Send the request by using IOrganizationService.Execute.
  4. Verify that only one new column definition was returned to represent the choice column that you created.
  5. Save the RetrieveMetadataChangesResponse.ServerVersionStamp value for use in the next request.
  6. Add that choice column data to the cache.

Delete choice column

Delete the choice column that you created earlier.

Detect deleted column

  1. Create a new instance of RetrieveMetadataChangesRequest and set the Query parameter to the original query.
  2. Set the RetrieveMetadataChangesRequest.ClientVersionStamp to the value returned from the second request.
  3. Set the RetrieveMetadataChangesRequest.DeletedMetadataFilters to DeletedMetadataFilters.Attribute because you're only looking for deleted column definitions.
  4. Send the request by using IOrganizationService.Execute.
  5. Find the ID of the deleted choice column in the RetrieveMetadataChangesResponse.DeletedMetadata, using DeletedMetadataFilters.Attribute as an index value for the collection.
  6. Remove the column definition from the cache.
  7. Write a list of all the current columns in the cache.

Clean up

No clean up is required because all data created by this sample is deleted.