Tuesday, August 13, 2019

How to remove non-alphanumeric characters in Dynamic 365 CRM


Here is a JavaScript method to remove non-alphanumeric character and can be called on save event in Dynamic CRM

function OnSaveRemoveCharacter(executionContext)
{
  formContext = executionContext.getFormContext();
   
  var alphaNumericChar = formContext.getAttribute("new_textfield").getValue();

  // I have replaced here with space , you can do without space like ''
  alphaNumericChar = alphaNumericCode.replace(/[^a-z0-9+]+/gi, ' ');

  formContext.getAttribute("new_textfield").setValue(alphaNumericCode);

  // Set field setsubmit mode
  formContext.getAttribute("new_textfield").setSubmitMode("always");
}

No comments: