Have you ever wished that CRM had a composite key to reference the entity data? Guess what your wishes are now granted With Spring release, CRM now makes keys available for all entities.
You can create a composite key/alternate key for multiple columns like Account Name + Account suburb or any such combinations. So the question in many people's mind would be how does this help?
With this, you can now define a non-clustered index in the database. This will allow quick searches as now non-clustered index can be created for alternate keys and that means table scans will not be necessary and the records can be fetched a lot faster.
This can also be used to identify data imported into CRM from external system. Please note alternate key is not GUID. It is new way to allow external systems store CRM reference.
Here is the code example which uses alternate keys
string accountNumber = "12345";
Money NewCreditLimit = new Money(5000000);
string newPrimaryContact = name1@company.com;
using (OrganizationServiceProxy service = GetOrgService())
{
Entity account = new Entity() { LogicalName = "account",
KeyAttributes = { { "new_subcode", "FABRIKAM" },
{ "new_subacctcode", accountNumber } }
};
account["primarycontactid"] = new EntityReference("contact", "emailaddress1", newPrimaryContact);
UpdateRequest request = new UpdateRequest();
request.Target = account;
UpdateResponse response = (UpdateResponse)service.Execute(request);
}
Further details on alternate keys available on following MSDN article:
https://msdn.microsoft.com/en-us/library/dn932139.aspx
Looking forward to more tightly integrated systems.
This can also be used to identify data imported into CRM from external system. Please note alternate key is not GUID. It is new way to allow external systems store CRM reference.
Here is the code example which uses alternate keys
string accountNumber = "12345";
Money NewCreditLimit = new Money(5000000);
string newPrimaryContact = name1@company.com;
using (OrganizationServiceProxy service = GetOrgService())
{
Entity account = new Entity() { LogicalName = "account",
KeyAttributes = { { "new_subcode", "FABRIKAM" },
{ "new_subacctcode", accountNumber } }
};
//update account
account["creditlimit"]
= NewCreditLimit;account["primarycontactid"] = new EntityReference("contact", "emailaddress1", newPrimaryContact);
UpdateRequest request = new UpdateRequest();
request.Target = account;
UpdateResponse response = (UpdateResponse)service.Execute(request);
}
Further details on alternate keys available on following MSDN article:
https://msdn.microsoft.com/en-us/library/dn932139.aspx
Looking forward to more tightly integrated systems.
Your blog site is excellent. Say thanks to you truly for providing plenty of both useful and interesting advise. I will bookmark your website and will be absolutely coming back. Again, I truly appreciate all your work furthermore providing plenty of worthwhile info for the audience.
ReplyDeleteMicrosoft Dynamics CRM Training | Microsoft Dynamics CRM Consulting Services | Microsoft Dynamics AX Training