Personalized Community is here!
Quickly customize your community to find the content you seek.
Have questions on moving to the cloud? Visit the Dynamics 365 Migration Community today! Microsoft’s extensive network of Dynamics AX and Dynamics CRM experts can help.
2021 Release Wave 2Discover the latest updates and new features releasing from October 2021 through March 2022.
2021 release wave 2 plan
The FastTrack program is designed to help you accelerate your Dynamics 365 deployment with confidence.
FastTrack Program | Finance and Operations TechTalks | Customer Engagement TechTalks | Upcoming TechTalks | All TechTalks
Hi, In my CRM Plug in, after the entity is created, I need to get its Guid.
This is what I did:
Guid entityId = Guid.Empty;
entity = CreateNewEntity("Account_logicalname", "accountnumber"); //here the entity is created.
entityId = (Guid)entity.Id; //this code does not work, it the entityId returns "00000000-0000-0000-0000-000000000000 "
is my codes wrong ?
Are there any other method to get the Guid of an given entity in this situation?
Thank you so much for your help,
please post the code in your CreateNewEntity() function here.
Hi friends, CRM developer here. I faced the same issue for my site (techloyce.com) It is correct that the logical name of the entity with the suffix 'id' is commonly used. Another way to find out is to use the logical name of the entity:
The primary key value will be the other property returned.
As I mentioned the entity is created through CreateNewEntity() function, I can see the attributes through my debug codes,
my question is the code below it: entityId = (Guid)entity.Id; I am not sure this is right way to get the Guid of entity.
Any ideas? thanks again
Hi RizzKh2, thanks a lot for your help,
"Another way to find out is to use the logical name of the entity:", could you provide an example code of how to do it? thanks
If your function CreateNewEntity() is returning Entity object, then entity.Id should give a GUID of a record. Since you're saying it is give empty GUID, we need to take a look at the code block inside the CreateNewEntity() method to check if anything wrong in returning value.
Thanks again for your help, yes, you are right, it may be there is an issue of the entity was generated,
The create entity was bit long, I post part of here with my comments:
Entity entity = new Entity("crm_accountlogigicname");
entity.Attributes["lbgtqcompensationreceived"] = new OptionSetValue(747220000);
entityId = localContext.OrganizationService.Create(entity);
localContext.Trace("before return entity :" + "entity.Id=" + entity.Id.ToString() + "entityId:" + entityId);
//the above code I got: entity.Id= 00000000-0000-0000-0000-000000000000 entityId: 24ace33e-5dd3-ac11-8217-000d3ae8cbc7
//return entityId; // old code
please let me know if you have any idea for further debugging, thanks again
I am thinking my this line of code: entityId = localContext.OrganizationService.Create(entity); it is returning the entityId, however, the entity was not actually created, thus the entity.Id = 00000000-0000-0000-0000-000000000000 , how is that possible? any way to fix it?
If you need only GUID of the record, do not return entity, return entityId. service.Create function returns GUID, but won’t set it to entity object. If you need both entity object and GUID, set GUID to entity’s Id and return entity, as below.
entity.Id = entityId;
Hi Charan, Thank you so much again,
Yes, in my case, I need to return entity and also need entityId as well,
Therefore, your code of "entity.Id = entityId;" resolves my problem. I marked it resolved, much appreciated!
I don't know the entity.Id needs to assign GUID before return the entity.
Sorry, one more question:
I have these codes below:
entityId = localContext.OrganizationService.Create(entity); //this one is compiled OK, it returns the entityId,
entityId = localContext.OrganizationService.Update(entity); //but I have compile time error for this one, it shows "Cannot implicitly convert type 'void' to System.Guid, "
if localContext.OrganizationService.Update(entity) does not return entityId, then how can I get the entityId in this case, I do need the entityId.
Is there anyway to fix this compile time error?
Update function doesn’t return any value. In order to update a record, you must know GUID of the record in advance before calling update function and set it to entity object as below.
entity.Id = new Guid(“<GUID>”);
Business Applications communities