web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How can I remove non-alphanumeric characters from a field using an on-save event?

(0) ShareShare
ReportReport
Posted on by

Hello,

 

I am trying to remove non-alphanumeric characters from a field using an on-save event.  Here is what I have in my OnSave event so far:

 

 (DELCHR(String,'=','!|@|#|$|%');

 

What else do I need to add to get this event to work?  I have not created OnSave events in the past and am new to JavaScript.  When I try to execute the event in my form, I receive an error telling me I am missing the ']' symbol, which I do not believe is the issue.

 

Thanks!

*This post is locked for comments

I have the same question (0)
  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi Try with this  -

    function OnSaveRemoveCharacter(executionContext) {
    formContext = executionContext.getFormContext();
    formContext.getAttribute("new_code").setSubmitMode("always"); // Set field setsubmit mode
    var alphaNumericCode = formContext.getAttribute("new_code").getValue();
    alphaNumericCode = alphaNumericCode.replace(/[^a-z0-9+]+/gi, ' '); // I have replaced here with space , you can do without space like ''
    formContext.getAttribute("new_code").setValue(alphaNumericCode); // Replace Field name 

    }

  • Community Member Profile Picture
    on at

    Hi Goutam,

    Thank you for your reply.  I tried your suggestion and received the following error: "One of the scripts for this record has caused an error. For more details, download the log file.

    Web resource method does not exist: Remove Non-Alphanumeric Characters".

    How can I fix this?  "Remove Non-Alphanumeric Characters" is the name of my event.

    Thanks!

  • gdas Profile Picture
    50,091 Moderator on at

    Can you share error screenshot.

  • Community Member Profile Picture
    on at

    Yes, please see below:

    2480.ScriptError.PNG

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    :) Seems you did silly mistake. Please follow below steps  -

    1. In my above code replace the field name "new_code" with the field name which you want to remove no alpha numeric character.

    2. Now copy and paste the code in the JS web-resource .

    3. Go to form properties , under onsave give the method name   OnSaveRemoveCharacter

    4. Dont forget to pas execution context. (docs.microsoft.com/.../clientapi-execution-context)

    For more information please have a look how to register function in Dynamics 365.

    carldesouza.com/.../

  • Community Member Profile Picture
    on at

    Goutam,

    I believe I've followed each step you mentioned.  However, I am still receiving the following error:

    ScriptError3.PNG

    Any ideas how I can fix this?

    Also, the "new_code" should be replaced with the field name, not the field's display name, correct?

  • Suggested answer
    Vipin J Profile Picture
    1,603 on at

    new_transferfromcode

    you might forgot to change the above field name, if you are updating and replacing in the same field. 

    Regards,

    Vipin 

    https://vjcity.blogspot.com/2019/08/guidelines-to-write-good-javascript.html

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Make sure you replace new_transferfromcode with field name  last line as well -

    formContext.getAttribute("new_transferfromcode").setValue(alphaNumericCode); //replace new_transferfromcode

  • Community Member Profile Picture
    on at

    That worked!  Thank you so much for the help!

  • Suggested answer
    Vipin J Profile Picture
    1,603 on at

    As you said you are new to Javascripting in Dynamic CRM,

    Here are some of the post which you can look for

    [View:https://vjcity.blogspot.com/search/label/Dynamic%20CRM%20JavaScript:750:50]

    https://vjcity.blogspot.com/2019/08/guidelines-to-write-good-javascript.html

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans