Hi Victor,
As mentioned above, you cannot create user for CRM online directly using CRM SDK. You need to create users in O365 and assign licence. Once the license is assign you user will be created in your CRM organization.
Alternatively, you could use the below code for existing users-
For currently logged in user use WhoAmIRequest message-
=========================
var userId = ((WhoAmIResponse)service.Execute(new WhoAmIRequest())).UserId;
var userRef = new EntityReference("systemuser", userId);
=========================
To retrieve a different user by username
=============================
QueryExpression userQuery = new QueryExpression
{
EntityName = "systemuser",
ColumnSet = new ColumnSet("systemuserid"),
Criteria = { Conditions = { new ConditionExpression("domainname", ConditionOperator.Equal, "username@testorg.onmicrosoft.com") } }
};
var userResults = service.RetrieveMultiple(userQuery);
var retrievedUser = userResults.Entities.FirstOrDefault();
var userRef = retrievedUser.ToEntityReference();
=============================
Once you get the user reference, you can then set the user referenc directly to your other code. E.g.
clinic.new_ClinicCoordinator = userRef ;
Hope this helps.