USD – RunXrmCommand to Set Focus

A quick post …. In Unified Service Desk (USD) for Microsoft Dynamics CRM you might want to set focus to a particular field on a CRM form.

There might be multiple situations when you’d like to set focus to a particular field on a CRM form from a USD action. Maybe you’ve just given a message that a field is invalid, so it would make life simpler for the agent to also position them on that field. This is simple to do, here is how.

Create an action to set the focus.

Below you can see I have created an action for my incident hosted control, this logic will work with any CRMPage. The action is “RunXrmCommand”. This is a simple command that injects javascript into the CRM form. So in my example I ran the command to give focus to the description field on my incident.

Xrm.Page.ui.controls.get(“<<field name>>”).setFocus();

You can also get a little more complicated! You can see in the example below that I have created a small function that will give the description field focus if it is blank but will otherwise give focus to the subject field. This might not be the best example in the world but hopefully it points to some syntax that you might find quite useful!

Notice, I am also using a getValue command here to look at the descriptions current value.

Xrm.Page.getAttribute(“description”).getValue();

Hopefully anyone familiar with writing JavaScript for CRM forms will find this action easy to implement. Enjoy. J

3 thoughts on “USD – RunXrmCommand to Set Focus

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

  2. Pingback: USD – The Book - Microsoft Dynamics CRM Community

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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