USD – Return results from a RunXrmCommand

In Unified Service Desk (USD) for Microsoft Dynamics CRM it is possible to use RunXrmCommand to run commands in the context of the currently loaded form.

This is great but what if you wanted to “grab” the results into to then use them in future actions. One advantage being that you would be looking at the value the user has just entered, as the CRM record might not be saved this could differ from what is already in the context or actually saved on the CRM record.

Here is how this can be achieved….

In my example I am going to “grab” the currently entered mobile phone number for a contact. First of all, create an action call that runs a “RunXrmCommand”. The simple code I inserted into the data portion is shown below.

function RunXrmCommand_Example() {
  var currentMobile = Xrm.Page.getAttribute("mobilephone").getValue();
  return currentMobile;

The “important” line of code is “return currentMobile;”, this is going to give me a return parameter containing the current mobile phone number. Notice below that I had changed the phone number but hadn’t saved it. I then ran my action to see what results I got.

Below you can see that I have run this example action in the debugger. Obviously you’d need to call  action(s) from appropriate events in your application, I’m just running it like this to explain how it operates.

Having successfully run the action, I then looked at the Data Parameters. (Not forgetting to refresh them!) Below you can see highlighted a return parameter containing the current mobile number for the contact.

Notice how the parameter has been named, it is the name of the action that returned the value. So to access this value I would use a replacement parameter such as “[[$Return.Contact – Current Mobile]]”

To illustrate how this value can now be used in other actions I have shown a display message action below. Again just as an example, you’d have hopefully have an action that does something much more interesting!

Hopefully you will have found this post useful and will see how to adapt this concept to benefit you USD application. J

One thought on “USD – Return results from a RunXrmCommand

  1. Pingback: USD – The Book | Microsoft Dynamics CRM and Unified Service Desk

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s