Using Expression Builder to Open Agent Scripts Dynamically

1 Comment

In this post, we will look at the Customer Service workspace functionality to open Agent Scripts dynamically based on criteria using the Expression Builder.

First, let’s look at setting this up. Go to the Customer Service workspace admin app and select Session Templates, then open your session template:

We have a session template called Test Case Template, which will open when a case is initiated in CSw:

There are 2 agent scripts assigned to this session template:

  • Agent script session template
  • Agent script session template 2

The steps in each agent script look different, as you would expect.

Case trial agent script has:

Case trial agent script 2 has:

Now, to open these scripts dynamically, select Enable build expression, then click the Build Expression button:

This opens like below. Expand the Condition:

You will see something like this. Here we can define the condition and then which agent script to open given the condition:

Let’s go through an example. A case has a field called “Subject”. Let’s say if the subject of a case equals “auto-drip” then we want to open “Case trial agent script 2”:

We can get the name of the field through a query (easy way to build this would be through Dataverse REST Builder tool in XrmToolbox):

And this will give us the fieldname:

Now we can paste this into our expression like below. We will need to wrap it with $anchor. like below:

${anchor._subjectid_value@OData.Community.Display.V1.FormattedValue}

For the if true, we’re going to select an agent script connector:

Then set default agent script:

And let’s select Case trial agent script 2:

Repeat for if false, and we will select Case trial agent script 1:

Note the “set default agent script” title in blue above, you can call this anything meaningful.

Then save and close, and we can try this out. Refresh the Customer Service workspace app if you already had it open. Let’s select an “auto-drip” subject case. We see “case trial agent script 2” opens:

And if we open a non auto-drip case such as water-supply, we see the case trial agent script opens:

We are now opening our agent scripts dynamically.

Let’s now use OData to query in our Expression Builder to see another way of dynamically opening agent scripts. The OData queries are in the format below per the Microsoft documentation:

In our case, let’s use the title of the case as an example. Our query is below. Note the format:

${$odata.incident.title.?$filter=incidentid eq ‘${anchor.incidentid}’&$select=title}

Now let’s change our query to below, and save and close:

We see our agent script opens as expected:

 

THANKS FOR READING. BEFORE YOU LEAVE, I NEED YOUR HELP.
 

I AM SPENDING MORE TIME THESE DAYS CREATING YOUTUBE VIDEOS TO HELP PEOPLE LEARN THE MICROSOFT POWER PLATFORM.

IF YOU WOULD LIKE TO SEE HOW I BUILD APPS, OR FIND SOMETHING USEFUL READING MY BLOG, I WOULD REALLY APPRECIATE YOU SUBSCRIBING TO MY YOUTUBE CHANNEL.

THANK YOU, AND LET'S KEEP LEARNING TOGETHER.

CARL

https://www.youtube.com/carldesouza

 

ABOUT CARL DE SOUZA

Carl de Souza is a developer and architect focusing on Microsoft Dynamics 365, Power BI, Azure, and AI.

carldesouza.comLinkedIn Twitter | YouTube

 

One Response to Using Expression Builder to Open Agent Scripts Dynamically

  1. Hi, thanks for a great blog. I have a question, we have a DTAP-setup and release session templates and agent scripts through managed solutions. What we see is the agent scripts get a new GUID on each environment. So setting the default agent script using the expression builder doesn’t work as it can’t find the correct GUID on every subsequent environment. And we have to manually update the session templates.

    I’ve tried to use the odata-syntax to dynamically find the right agent script, but it doesn’t work. Can we use odata in the set default agent script action? Do I have the correct syntax or should we release using some other mechanism/tool to maintain GUID’s?

    Example: ${$odata.msdyn_productivityagentscripts.msdyn_productivityagentscriptid.?$select=msdyn_productivityagentscriptid&$filter=msdyn_name eq ‘Case trial agent script’}

Leave a Reply

Your email address will not be published. Required fields are marked *