Hi,
I am new to the dynamics environment.
i am trying to appoint a case based on the location and skills using plugins.
i am using two entities that is : Case and User.
i have created 3 custom fields on case : Case origin(OPTIONSET): 1.Mumbai:277570001, 2.Goa:277570002 ,3. Delhi:277570003
and related to(OPTIONSET) :1. Computer devices, 2.mobile devices, and assigned to field(Lookup to user) which is locked and should be populated once the case record is assigned.
Similarly, I have created two custom fields on user : Location(Optionset): 1.Mumbai :277570001, 2.Goa: 277570002, 3.Delhi:277570003
and Skills(Optionset ):1. Computer devices:277570008, 2.Mobile Devices:277570009.
I have written the following code:
if (caseentity.LogicalName == "incident")
{
var location = caseentity.Attributes["del_caseorigin"].;
var issue = caseentity.Attributes["del_relatedto"].;
//2
QueryExpression query = new QueryExpression("systemuser");
query.ColumnSet = new ColumnSet(new string[] { "systemuserid", "fullname" });
FilterExpression filter1 = new FilterExpression(LogicalOperator.And);
filter1.Conditions.Add(new ConditionExpression("del_location", ConditionOperator.Equal, location));
filter1.Conditions.Add(new ConditionExpression("del_skills", ConditionOperator.Equal,issue ));
query.Criteria = filter1;
//RETRIEVE ALL USER RECORDS BASED ON CONDITION AND STORE IT IN ENTITY COLLECTION
EntityCollection userrecords = service.RetrieveMultiple(query);
//? //3 How to select random record in entity collection ?
//USING THE FIRST USER TO ASSIGNE THE CASE
Entity singleuserreocrd = userrecords.Entities.FirstOrDefault();
//ACCESSING THE COLUMN
EntityReference userid =(EntityReference) singleuserreocrd.Attributes["systemuserid"];
//assigning the case
caseentity["ownerid"] = new EntityReference("systemuser", userid.Id);
caseentity["del_assignedto"] = new EntityReference("systemuser",userid.Id);
}
I am getting an error while retrieving the users.
Any Guidance to effectively solve this issue would be highly appreciated.