Does anyone know a simple way how I can retrieve the GUID of specific record using it's name, in C#?
Entity: msdyn_contractorganizationalunitid
Record Name: Fabrikam Global
*This post is locked for comments
Does anyone know a simple way how I can retrieve the GUID of specific record using it's name, in C#?
Entity: msdyn_contractorganizationalunitid
Record Name: Fabrikam Global
*This post is locked for comments
Hope this link will help you with simplest c# code to retrieve entity record guid from entity name :
community.dynamics.com/.../242514
Regards,
Pranesh
Hi Redhead,
Did you resolved your issue?
Best Regards,
Shahbaaz
You need to use Queryexpression as we did in above code...you need to keep in mind you pass correct entity name in entity, schema name of filed in condition as we did above.
Thanks,
Shahbaaz
How can i query a second and third entity in another records as we have just done in the same code?
Id believe i need to set these two fields which are both lookup's also:
ProjectDetail["msdyn_workhourtemplate"] to be set too the record with the name "Default Work Template";
ProjectDetail["msdyn_projecttemplate"] to be set too the record with the name "TEST-Template";
In the above code you are setting value for "msdyn_projectid","msdyn_subject" and "msdyn_contractorganizationalunitid" is there any other field on Form which is Required field, if yes then you have to set that field value in above code.
Let me know if i am not clear.
Best Regards,
Shahbaaz
Thanks, I now get the following error:
Entered CrmVSSolution1.ProjectCreation.PostOperationquoteCreate.Execute(), Correlation Id: e44ea241-62d9-4716-a070-5dd1810f787b, Initiating User: 21cfc663-f73f-4b21-a6a4-438c074c5ab1
Exception: System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]: Value cannot be null.
Parameter name: input (Fault Detail is equal to Exception details:
ErrorCode: 0x80040265
Message: Value cannot be null.
Parameter name: input;
[Microsoft.Dynamics.ProjectService.Plugins: Microsoft.Dynamics.ProjectService.Plugins.PreProjectCreate]
[c9b474ef-86e4-e411-80e4-00155db85902: PreProjectCreate]
Starting sync workflow 'Due date validation', Id: 6a9638da-c327-e811-a959-002248004894
Entering ConditionStep1_step:
Sync workflow 'Due date validation' completed successfully
Starting sync workflow 'Actual end date validation', Id: 799638da-c327-e811-a959-002248004894
Entering ConditionStep1_step:
Sync workflow 'Actual end date validation' completed successfully
Entered Microsoft.Dynamics.ProjectService.Plugins.PreProjectCreate.Execute(), Correlation Id: e44ea241-62d9-4716-a070-5dd1810f787b, Initiating User: 21cfc663-f73f-4b21-a6a4-438c074c5ab1
Exiting Microsoft.Dynamics.ProjectService.Plugins.PreProjectCreate.Execute(), Correlation Id: e44ea241-62d9-4716-a070-5dd1810f787b, Initiating User: 21cfc663-f73f-4b21-a6a4-438c074c5ab1
TimeSta...)., Correlation Id: e44ea241-62d9-4716-a070-5dd1810f787b, Initiating User: 21cfc663-f73f-4b21-a6a4-438c074c5ab1
Exiting CrmVSSolution1.ProjectCreation.PostOperationquoteCreate.Execute(), Correlation Id: e44ea241-62d9-4716-a070-5dd1810f787b, Initiating User: 21cfc663-f73f-4b21-a6a4-438c074c5ab1
Error Message:
Unhandled Exception: Microsoft.Xrm.Sdk.InvalidPluginExecutionException: OrganizationServiceFault
Hi Redhead,
I think your above code is correct, please use below code and let me know if you are getting any error.
Entity Project = context.InputParameters["Target"] as Entity;
Entity ProjectDetail = new Entity("msdyn_project");
ProjectDetail["msdyn_projectid"] = new EntityReference() { Id = Project.Id, LogicalName = Project.LogicalName };
ProjectDetail["msdyn_subject"] = "New Project";
QueryExpression getguid = new QueryExpression()
{
EntityName = "msdyn_organizationalunit",
Criteria ={
Conditions =
{
new ConditionExpression("msdyn_name",ConditionOperator.Equal,"Fabrikam Global"),
},
}
};
EntityCollection retrievegetguid = service.RetrieveMultiple(getguid);
if (retrievegetguid.Entities.Count > 0)
{
Guid Id = retrievegetguid.Entities[0].Id;
ProjectDetail["msdyn_contractorganizationalunitid"] = new EntityReference("msdyn_organizationalunitid", Id);
}
service.Create(ProjectDetail);
Thanks,
Shahbaaz
Yes i still get an error: A local or parameter named 'ProjectDetail' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter.
QueryExpression getguid = new QueryExpression()
{
EntityName = "msdyn_organizationalunitid",
Criteria ={
Conditions =
{
new ConditionExpression("msdyn_name",ConditionOperator.Equal,"Fabrikam Global"),
},
}
};
EntityCollection retrievegetguid = service.RetrieveMultiple(getguid);
if (retrievegetguid.Entities.Count > 0)
{
Entity ProjectDetail = new Entity("projectdetail");
Guid Id = service.Create(ProjectDetail);
ProjectDetail["msdyn_contractorganizationalunitid"] = new EntityReference("msdyn_organizationalunitid", Id);
}
nothing, forget that, are you still facing any issue??
if not that dont forget to close the thread by marking answer Verified.
Best Regards,
Shahbaaz
Hi again, when you say " //Pass the project Detail Guid here which record you want to update" i'm not actually updating one, instead i;m creating a new project and including this field.
Entity Project = context.InputParameters["Target"] as Entity;
Entity ProjectDetail = new Entity("msdyn_project");
ProjectDetail["msdyn_projectid"] = new EntityReference() { Id = Project.Id, LogicalName = Project.LogicalName };
ProjectDetail["msdyn_subject"] = "New Project";
QueryExpression getguid = new QueryExpression()
{
EntityName = "msdyn_organizationalunit",
Criteria ={
Conditions =
{
new ConditionExpression("msdyn_name",ConditionOperator.Equal,"Fabrikam Global"),
},
}
};
EntityCollection retrievegetguid = service.RetrieveMultiple(getguid);
if (retrievegetguid.Entities.Count > 0)
{
Guid Id = retrievegetguid.Entities[0].Id;
ProjectDetail["msdyn_contractorganizationalunitid"] = new EntityReference("msdyn_organizationalunitid", Id);
}
service.Create(ProjectDetail);
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156