I have Created an User with a Business Unit for Dynamics 365 through .net core console application. But wondering how to create license for that user from the console application.
I have tried to insert values for License related fields in systemuser entity manually
public static Guid CreateUsers(IOrganizationService _orgService, Dynamics365_User dynamics365_User)
{
Entity systemuser = new Entity("systemuser");
systemuser.Attributes.Add("domainname", dynamics365_User.domainname);
systemuser.Attributes.Add("firstname", dynamics365_User.firstname);
systemuser.Attributes.Add("lastname", dynamics365_User.lastname);
systemuser.Attributes.Add("internalemailaddress", dynamics365_User.internalemailaddress);
systemuser.Attributes.Add("isdisabled", dynamics365_User.isdisabled);
//systemuser.Attributes.Add("islicensed", dynamics365_User.islicensed);
systemuser.Attributes.Add("userlicensetype", dynamics365_User.userlicensetype);
systemuser.Attributes.Add("caltype", new OptionSetValue(Convert.ToInt32(dynamics365_User.CalType)));
//systemuser.Attributes.Add("applicationid", Guid.Parse("b28eba1a-bc54-408d-bc45-ddaa44f6918f"));
//systemuser.Attributes.Add("applicationid", Guid.Parse("c4c6b5e8-050a-4bc0-a419-79e55345f751"));
//systemuser.Attributes.Add("applicationid", new Guid("80af87d0-db9c-48b6-b561-9c75ec8489f0"));
//systemuser.Attributes.Add("azureactivedirectoryobjectid", new Guid());
systemuser.Attributes.Add("businessunitid", new EntityReference
{
Id = dynamics365_User.businessunit.Id,
LogicalName = dynamics365_User.businessunit.LogicalName,
Name = dynamics365_User.businessunit.Name
});
Guid userid = _orgService.Create(systemuser);
dynamics365_User.firstname, dynamics365_User.lastname, conn.OrganizationServiceProxy,ref temp);
return userid;
}