{Dynamics CRM} Not getting latest Text field value on click of custom ribbon button in CRM 2013

Recently in my project, I was faced with the above problem. The exact scenario is explained below.

I have a text field for entering the Device Id in CRM. The user enter a value in the textbox and clicks on the the ‘Determine 54-90’ custom ribbon button without tabbing out from the textbox as shown in the screenshot below.


The problem is inside the function that is called from ribbon button click, the value obtained using Xrm APIs for this Device ID field does not reflect the latest value entered. This is because the user has not tabbed out from the field before clicking the ribbon button.

In CRM 2011, the following code during onload of the form would resolve the issue.

document.getElementById(“<controlid>”).onblur = function()
var latestValue = document.getElementById(“<controlid>”).value;

However the same code might not work in CRM 2013 because in CRM 2013, the rendering model has changed completely. On load of the form all the controls are loaded as div and the value of the control is shown inside the span of the Div.

The moment the user clicks on the text field, it becomes an input field. So the scenario would be:

1. if the user don’t tab out of the textfield, check for the latest field value using a jquery

2. If the user has tabbed out, get the value of the textfield using the XRM API

the code below achieves the same.

if ($(“input[attrname='[field_logicalname]'”).length > 0) {


Hope this helps!


4 thoughts on “{Dynamics CRM} Not getting latest Text field value on click of custom ribbon button in CRM 2013

    1. Hi Ravi,

      Thanks for reading my blog post.

      I am not sure if that is fixed. I have CRM 2013 SP1 installed on my machine and still I can reproduce this.

      I feel its more of because of the way framework is designed. CRM only takes the fields which are dirty. When you click the ribbon button immediately, the onchange of the field does not fire. Hence the field is not dirty and hence you get the old value.

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s