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)

setRequiredLevel("none") not working in CRM 2013 for a scenario

(0) ShareShare
ReportReport
Posted on by 58

Hi,

We have a scenario where all mandatory fields have to be ignored during an operation and save should be triggered. We are doing this in JavaScript with the below code:

clearAllSections();
Xrm.Page.data.entity.save();

clearAllSections = function () {
try {
var attributes = Xrm.Page.data.entity.attributes.get();
for (var i in attributes) {
Xrm.Page.getAttribute(attributes[i].getName()).setRequiredLevel("none");
}
}
catch (e) {
alert("Error clearing requirements in field : " + attributes[i].getName());
}
}

System is not performing the save operation and is throwing message to fill the mandatory fields. When I debug the JS and check getRequiredLevel() of those fields, it is set to "none" itself.

Any idea why system is still asking to fill the mandatory fields even though requiredLevel is none? The fields are Optional and are set as required fields during OnLoad depending on various Business conditions.

*This post is locked for comments

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

    Hi ,

    How you are making mandatory those fields ? Are those attributes set business required in the field definition?

    Try to do few fields and see which field is not working.

  • surajcs55 Profile Picture
    58 on at

    Hi Goutam,

    We are setting those fields as mandatory on page load only. Not at the field level. Once we are done executing the 'clearAllSections' function, i went in and checked the requiredlevel for all fields. it is showing up as 'none". Still system valdiates for required fields on OnSave.

  • gdas Profile Picture
    50,091 Moderator on at

    If you set mandatory in the form onload which means when you save the records after save immediately page load will call and onload method again fire to make field mandatory.

    What are the fields you have  set mandatory ?while saving the records all those are showing mandatory or few of them are showing mandatory?

    While you are saving record by any chance is there any possibility  , same mandatory set function are calling .

  • surajcs55 Profile Picture
    58 on at

    Only few of the records are showing up as mandatory. For few, the setRequiredLevel("none") works fine. But for the records which show up as mandatory, the requiredLevel is none itself.

    No other function is called during save. After saving, the page reloads and it is working as expected. But the save operation itself is not getting  triggered when I have these fields marked as mandatory.

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