Using RunXrmCommand in USD to Populate Fields in Dynamics 365

Unified Service Desk (USD) for Dynamics 365 is a powerful tool that allows customer service representatives to manage customer interactions efficiently. One of the features of USD is the ability to execute Dynamics 365 SDK JavaScript through the RunXrmCommand action. This feature enables the injection of JavaScript code directly into a Dynamics 365 form, allowing for automated actions such as populating fields dynamically.

Scenario Populating a Blank Subject Field on a Task Form

Imagine a scenario where a customer service representative opens a Task form in USD, and the subject field is blank. To streamline operations, we want to automatically populate this subject field with a predefined message.

Step 1. Define the JavaScript Command

First, we need to define the JavaScript code that will populate the subject field. The following JavaScript code sets the value of the subject field on a Task form.

Xrm.Page.getAttribute("subject").setValue("Follow-Up Task Using RunXrmCommand");
Xrm.Page.data.entity.save();

This code retrieves the subject attribute of the form, sets its value to "Follow-Up Task Using RunXrmCommand," and then saves the form.

Step 2. Create a USD Action Call

Next, we create an action call in USD to execute the above JavaScript code using the RunXrmCommand.

  1. Open USD Configuration: Navigate to the USD configuration page in Dynamics 365.
  2. Create a New Action Call: Go to Action Calls and create a new action call.
  3. Configure the Action Call
    • Name: PopulateSubjectField
    • Hosted Control: Select the hosted control related to the Task entity.
    • Action: RunXrmCommand
    • Data: Enter the JavaScript code. Make sure to wrap it in a function as shown below.
function() {
    Xrm.Page.getAttribute("subject").setValue("Follow-Up Task Using RunXrmCommand");
    Xrm.Page.data.entity.save();
}

Step 3. Associate the Action Call with an Event

Now, you need to associate this action call with an appropriate event so that it executes when the Task form is loaded.

  1. Navigate to Events: Go to the Events section in USD.
  2. Select the Event: Choose the event related to the Task form loading, such as PageLoadComplete.
  3. Add the Action Call: Add the PopulateSubjectField action call to this event.

Step 4. Test the Configuration

After configuring the action call and associating it with the form load event, test the setup.

  1. Open USD: Launch the Unified Service Desk application.
  2. Open a Task Form: Navigate to a Task record.
  3. Verify the Subject: Check if the subject field is populated with the predefined message upon opening the Task form.

Additional Context and Best Practices

  • Validation: Ensure that your JavaScript code includes necessary validation checks to avoid overwriting existing subjects unintentionally.
  • Security: Only authorized personnel should have access to modify USD configurations and JavaScript injections to maintain the integrity and security of your Dynamics 365 environment.
  • Testing: Thoroughly test the action in a non-production environment to ensure it works as expected without causing any disruptions.
    Testing

Conclusion

By using the RunXrmCommand in USD, you can inject Dynamics 365 SDK JavaScript to automate field population and enhance the efficiency of your customer service representatives. This example demonstrates how to populate the subject field on a Task form automatically, but similar techniques can be applied to other fields and entities as well.


Similar Articles