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)

set field requirement dynamically using jquery on entity form

(0) ShareShare
ReportReport
Posted on by 344

Hi Team,

i have a piece of code to set field requirement  dynamically using the code below but it's not working properly, can some one help please

$(document).ready(function(){
$('#new_country').on('change', function() {
if ( this.value == '183240000') // if country ==uk
{

// make post code required
ValidatorEnable($("[id$='RequiredFieldValidatornew_poscode']")[0], true);
$('#new_poscode').parent().addClass('required');

}
else // any other country
{
/// make post code optional
ValidatorEnable($("[id$='RequiredFieldValidatornew_poscode']")[0], false);
$('#new_poscode').parent().removeClass('required');

}
});
});

*This post is locked for comments

I have the same question (0)
  • Nithya Gopinath Profile Picture
    17,078 on at

    Hi,

    You could use Javascript to set field requirement dynamically instead of Jquery. Then add this Javascript on-change event of the field.

    function SetRequiredLevel()
    {
    Xrm.Page.getAttribute("fieldname").setRequiredLevel("required");
    }

    https://msdn.microsoft.com/en-us/library/gg334409.aspx#BKMK_RequiredLevel

    You could also use Business Rules to set the required level of a field. 

    50525.1.PNG

    For more details, refer the link below.

    https://www.microsoft.com/en-us/Dynamics/crm-customer-center/create-business-rules-and-recommendations-to-apply-logic-in-a-form.aspx

    https://msdn.microsoft.com/en-in/library/dn481574.aspx

    Hope this helps.

  • Verified answer
    Colin V Profile Picture
    on at

    I would suggest checking out of the documentation that has a sample of adding a validator dynamically with JavaScript at the following link:

    community.adxstudio.com/.../custom-javascript

    ValidatorEnable does disable the control validation in the JS but it will persist on the postback, fail server-side validation and seem like it never got changed.  Your best to take the opposite approach, have no validator and then dynamically add a validator as shown in the sample.

  • scopecrm Profile Picture
    344 on at

    Thanks for the reply, i am not looking to do this in CRM entity form. I am trying to set this in Portal!

  • Verified answer
    Nithya Gopinath Profile Picture
    17,078 on at

    Hi,

    Please refer the link below.

    rajeevpentyala.com/.../useful-jscript-syntaxes-adx-portal

  • Suggested answer
    Summer Garg Profile Picture
    585 on at

    Hi scopecrm,

    Check below link to apply client side validations:

    crmhub.blogspot.com/.../apply-client-side-validation-in-d365-portal-ADX-Studio-Portal.html

    For more JS syntax ;

    crmhub.blogspot.com/.../how-to-use-java-script-in-adx-studio.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