As owner field is not a lookup field and its data type is GUID facing issues in adding the value to OwnerId field. Please suggest a way to make it happen. Thank you.
As owner field is not a lookup field and its data type is GUID facing issues in adding the value to OwnerId field. Please suggest a way to make it happen. Thank you.
hi
To set the value of the OwnerId field in Dynamics 365 when the value is not available as a lookup field, you can use the following steps:
Retrieve the user or team record for the desired owner and retrieve its GUID.
Set the OwnerId field value to the GUID retrieved in step 1.
Here's an example of how you can achieve this in C# code:
// Retrieve the user or team record for the desired owner
Entity owner = _service.Retrieve("systemuser", new Guid("USER_OR_TEAM_GUID"), new ColumnSet("systemuserid"));
// Set the OwnerId field value to the retrieved GUID
Entity myEntity = new Entity("my_entity");
myEntity.Attributes["ownerid"] = new EntityReference("systemuser", owner.Id);
_service.Create(myEntity);
In this example, replace "USER_OR_TEAM_GUID" with the GUID of the desired user or team record. Also, replace "my_entity" with the logical name of your entity.
Note that if you want to assign the record to a team, you can use the "team" logical name instead of "systemuser" in the EntityReference constructor.
DAniele
Hi partner,
Does it apply to the following scenarios?
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,280 Super User 2024 Season 2
Martin Dráb 230,214 Most Valuable Professional
nmaenpaa 101,156