Looking for PowerObjects? Don’t worry, you’re in the right place! We’ve been part of HCL for several years, and we’ve now taken the final step in our acquisition journey: moving our website to the HCL domain. Nothing else is changing – we are still fanatically focused on Microsoft Business Applications!

PowerObjects Blog 

for Microsoft Business Applications


Friday Flash Tip: Updating the Definition of an Entity in CRM Programmatically

Post Author: Joe D365 |

Did you know that you can programmatically update the definition of an entity in CRM using the UpdateEntityRequest class which contains the data that is needed to update the definition of an entity?

Here is a sample .net code that shows how to enable notes, queues, and disable mail merge on a custom entity named Lead Source.

using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Metadata;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Client.Services;

namespace testconsoleapp
{
public class UpdateEntityDefnition
{

private void EnableNotesQueuesDisableMailMergeOnLeadSource()
{

RetrieveEntityRequest retrieveLeadSourceEntityRequest = new RetrieveEntityRequest
{
EntityFilters = EntityFilters.Entity,
LogicalName = "po_leadsource"
};
using (var service = new OrganizationService("CrmConnection"))
{

RetrieveEntityResponse retrieveLeadSourceEntityResponse = (RetrieveEntityResponse)service.Execute(retrieveLeadSourceEntityRequest);
EntityMetadata leadSourceEntity = retrieveLeadSourceEntityResponse.EntityMetadata;

// Disable Mail merge
leadSourceEntity.IsMailMergeEnabled = new BooleanManagedProperty(false);
//Enable Queues
leadSourceEntity.IsValidForQueue = new BooleanManagedProperty(true);
// Enable Notes
UpdateEntityRequest updateOpportunityRequest = new UpdateEntityRequest
{
Entity = leadSourceEntity,
HasNotes = true
};
service.Execute(updateOpportunityRequest);
}
}
}
}

Where CRMConnection = the connection string to connect to the CRM org for which we are connecting to. That's it! Interested in learning anything and everything about Microsoft Dynamics CRM? Check out our Webinars on Demand, where you can watch great CRM content at any time!

Happy CRM'ing!

 

Joe CRM
By Joe D365
Joe D365 is a Microsoft Dynamics 365 superhero who runs on pure Dynamics adrenaline. As the face of PowerObjects, Joe D365’s mission is to reveal innovative ways to use Dynamics 365 and bring the application to more businesses and organizations around the world.

PowerObjects Recommends