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

Announcements

No record found.

News and Announcements icon
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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans