Question Status

Verified
Shin_K asked a question on 4 Mar 2015 5:24 PM

Hello,

I'm new to Dynamics CRM 2015, and was hoping for a point in the right direction.

My requirement is to obtain a value from an entity's text field that is of a specific format -- then parse and strip out the numbers, and set the value in a whole number field.

ex: Text field with value: I-2032-22. On record create, set another whole number field with value 203222. My research points me to creating a new custom action step, however, I'm wondering if there is a simpler method to accomplish this? Leveraging calculated field functionality would be ideal, but it doesn't seem to support converting data types. Any help is appreciated, thanks!

Reply
Verified Answer
Mamatha Swamy responded on 4 Mar 2015 5:53 PM

Hi,

AFAIK, calculated fields cannot be used for this purpose. You could use JScript (form/UI based record creation only) or plugin to fill in the other field.

Refer

blog.webfortis.com/ms-crm-2011-field-formatting-and-regular-expression-objects-with-javascript-7june12

msdn.microsoft.com/.../gg594416.aspx

msdn.microsoft.com/.../gg328490.aspx

Reply
Verified Answer
Mithilesh Kumar responded on 4 Mar 2015 9:52 PM

Hi Shin,

You cannot use Calculated Fields for this purpose. You need to build a Custom JScript which will run on the OnChange event of the Text Field.

As you said that the Format is fixed, you can try below simple function for the above Format

//Format (<Alphabet>-<Number>-<Number>)

function getNumberFromString(context){
 var fieldObj = context.getEventSource();
 if (fieldObj != null){
  var fieldValStr = fieldObj.getValue();
  var fieldValArr = fieldValStr.split("-");
  val fieldValNumber = fieldValArr[1] + fieldValArr[2];
  alert(fieldValNumber);  
 }
}

Use this function on the OnChange event of the Text field and make sure to pass the execution context.

Hope that helps

Thanks

Reply
Shin_K responded on 4 Mar 2015 11:20 PM

Thank you both for your answers. I think a plugin would best serve my specific purpose, so I have chosen that route. Will keep custom JScript in mind for future requirements as well!

Reply
Verified Answer
Mamatha Swamy responded on 4 Mar 2015 5:53 PM

Hi,

AFAIK, calculated fields cannot be used for this purpose. You could use JScript (form/UI based record creation only) or plugin to fill in the other field.

Refer

blog.webfortis.com/ms-crm-2011-field-formatting-and-regular-expression-objects-with-javascript-7june12

msdn.microsoft.com/.../gg594416.aspx

msdn.microsoft.com/.../gg328490.aspx

Reply
Verified Answer
Mithilesh Kumar responded on 4 Mar 2015 9:52 PM

Hi Shin,

You cannot use Calculated Fields for this purpose. You need to build a Custom JScript which will run on the OnChange event of the Text Field.

As you said that the Format is fixed, you can try below simple function for the above Format

//Format (<Alphabet>-<Number>-<Number>)

function getNumberFromString(context){
 var fieldObj = context.getEventSource();
 if (fieldObj != null){
  var fieldValStr = fieldObj.getValue();
  var fieldValArr = fieldValStr.split("-");
  val fieldValNumber = fieldValArr[1] + fieldValArr[2];
  alert(fieldValNumber);  
 }
}

Use this function on the OnChange event of the Text field and make sure to pass the execution context.

Hope that helps

Thanks

Reply