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)

Javascript - Set Required level doesn't work in Dynamic CRM

(0) ShareShare
ReportReport
Posted on by

Hello all,

I have tried to set validation using setRequiredLevel ,the validation showing  but when i am saving form then doesn,t work  that means not validate email field..

Xrm.Page.getAttribute("new_email").setRequiredLevel("required");

thanks
akram

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    BharatPremji Profile Picture
    2,485 on at

    Hi Akram,

    What are you trying to achieve here?

    The code you have pasted above with ensure the new_email field is a mandatory field, it will not validate if the user input is an email address.

    If you want email address validation you need to set that when you create the field:

    2671.Capture.PNG

    Bharat

  • Community Member Profile Picture
    on at

    Thank u for reply Bharat,

    My field is a single line text not email format,and validate if it is empty using javascript.

    thanks

    akram

  • Suggested answer
    BharatPremji Profile Picture
    2,485 on at

    Hi Akram,

    Where are you calling this this line of code:

    Xrm.Page.getAttribute("new_email").setRequiredLevel("required");

    Try putting it on load and see if the red asterix appears next to the field.

    I assume there's a reason you are not setting it to Business Required by default?

    Bharat

  • Community Member Profile Picture
    on at

    Thanks again for reply Bharat,

    I have called this on form load and also showing red asterix. and my field is not required by default but i want to make it required using javascript.

    that is possible or not.

    thanks

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi,

    How you are calling this script ? you have to call this onload.

    Please refer below.

    stackoverflow.com/.../setrequiredlevel-how-it-works

    Mansoor

  • Community Member Profile Picture
    on at

    Thank u for reply Mansoor,

    I have already tried this.

    thanks

    akram

  • Suggested answer
    BharatPremji Profile Picture
    2,485 on at

    Hi Akram,

    If your field has a red asterix by it and you do not enter a value and hit save, you should see something like this:

    31327.Capture.PNG

    which stops the save happening.

    Try putting some validation code on Save to see if there is something being passed to the field, something like:

    var newEmail = Xrm.Page.getAttribute("new_email").getValue();

    alert(newEmail);

    Bharat

  • Community Member Profile Picture
    on at

    The value from email field is comming null and also checked validation onsave event.

    thanks

    akram

  • BharatPremji Profile Picture
    2,485 on at

    Can you post a screenshot of:

    1. The On load code (and any other code you may have on the form)

    2.  The field showing the red asterix

    Also, do you have other mandatory fields on the the form?  If so, are you getting the same problem with those?

    Bharat

  • Community Member Profile Picture
    on at

    Hello Bharat,

    My code I have tried on both form load and onsave event.

    function businessAndPersionalValidate()

    {

    var business=Xrm.Page.getAttribute("new_business").getValue();

    var personal=Xrm.Page.getAttribute("new_personal").getValue();

    if(business==false && personal==false)

    {

    Xrm.Page.getAttribute("new_business").setValue(1);

    Xrm.Page.getAttribute("new_email").setRequiredLevel("required");

    }

    }

    load.jpg

    load.jpg

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