Add multiple preferred agent records
You can add multiple preferred agents to contact records at a time using the createRecord call to update the preferred agent entities, msdyn_preferredagent and msdyn_preferredagentcustomeridentity.
If you want to add multiple preferred agent routing records through the script, ensure that you map only three unique agents to a contact. If you add more than three agents, though the application displays all the mapped agents, work items are routed to the top three agents only. Agents are ordered based on the preference rating. If agents have the same preference rating, the application orders the agents based on the record creation timestamp.
You can also update or delete records using the updateRecord or deleteRecord calls.
Sample code syntax
A sample code syntax is as follows.
{
var contactid = "<replace_with_contactid_guid>";
var systemuserid = [`"<agentid-guid-1>"`,`"<agentid-guid-2>"`,`"<agentid-guid-3>"`]; // A maximum of three preferred agents can be mapped to one contact.
for (var i = 0; i < 2; i++)
{
var data =
{
"msdyn_name": "Preferred agent mapping",
"msdyn_recordId_contact@odata.bind": "/contacts("+contactid+")",
"msdyn_systemuserid@odata.bind": "/systemusers("+systemuserid[i]+")",
"msdyn_preferencerating": i+1,
"msdyn_recordtype": 192350001
}; // necessary fields for the entity record creation
Xrm.WebApi.createRecord("msdyn_preferredagent", data); // create record
}
}
Important
We recommend that you add the contact and preferred agent routing through the Preferred agent routing page.