Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

assign Case based on Location and skills of the user.

(0) ShareShare
ReportReport
Posted on by 5

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.

 

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,959 Super User 2024 Season 1 on at
    RE: assign Case based on Location and skills of the user.

    Hello,

    I have updated your code. Please copy below code and try -

    if (caseentity.LogicalName == "incident")
                    {
                        var location = ((OptionSetValue)caseentity.Attributes["del_caseorigin"]).Value;
                        var issue = ((OptionSetValue)caseentity.Attributes["del_relatedto"]).Value;
    
    
                        //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
                        Guid userid = (Guid)singleuserreocrd.Attributes["systemuserid"];
    
                        //assigning the case
                        caseentity["ownerid"] = new EntityReference("systemuser", userid);
                        caseentity["del_assignedto"] = new EntityReference("systemuser", userid);
    
                    }

    Please mark my answer verified if this is helpful!

    Regards,

    Bipin Kumar

    Follow my Blog: xrmdynamicscrm.wordpress.com/

  • empath-e CRM Profile Picture
    empath-e CRM 1,136 on at
    RE: assign Case based on Location and skills of the user.

    Can you not achieve this using the Case Routing Rules functionality?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,711 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans