Edit

Share via


Retrieve, update, and delete tables using the Dataverse SDK for .NET

Learn how to retrieve, update, and delete a table definition. This article uses the custom Bank Account table that you created in Create a custom table.

Retrieve and update a table

The following static DemonstrateRetrieveUpdateTable sample method retrieves a table definition by using the RetrieveEntityRequest class. It then updates the table to disable mail merge by setting the IsMailMergeEnabled property to false, and sets HasNotes to true in the UpdateEntityRequest to specify that the table should include a relationship to the Annotation table for the purpose of displaying notes.

static void DemonstrateRetrieveUpdateTable(IOrganizationService service, string LogicalName)
{
    RetrieveEntityRequest request = new RetrieveEntityRequest
    {
        EntityFilters = EntityFilters.Entity,
        LogicalName = LogicalName
    };
    RetrieveEntityResponse response = (RetrieveEntityResponse)service.Execute(request);
    EntityMetadata table = response.EntityMetadata;

    // Disable Mail merge
    table.IsMailMergeEnabled = new BooleanManagedProperty(false);
    // Enable Notes
    UpdateEntityRequest updateBankAccountRequest = new UpdateEntityRequest
    {
        Entity = table,
        HasNotes = true
    };

    service.Execute(updateBankAccountRequest);
}

Note

Learn about available options to retrieve table schema information.

Delete a custom table

The following static DeleteTable sample method uses the DeleteEntityRequest class to delete the table definition with the specified logical name.

static void DeleteTable(IOrganizationService service, string LogicalName)
{
    DeleteEntityRequest request = new DeleteEntityRequest()
    {
        LogicalName = LogicalName,
    };
    service.Execute(request);
}

See also

Customize table definitions
Create and update a table to send email activities to rows
Create a custom table