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 :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Java Script to make field Mandatory if A contains "XXX"

(0) ShareShare
ReportReport
Posted on by 108

Hi All,

I have a requirement to write a javascript, where A contains "XXX", then make B as Mandatory. I don't want to write in business rule, as I need the field "B"  to become mandatory before saving the form.

Could anyone please help me?

Cheers,

Saratha

I have the same question (0)
  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi,

    Just to share, you can achieve this in business rule as well which will make the field required before saving as well. if you still want to go with javaScript, you can start from this link-neilparkhurst.com/.../

    You can find some basic sample here (including setRequiredLevel): rkcrm.wordpress.com/.../

    Hope this helps

  • Poornimaa Profile Picture
    108 on at

    Hi Ravi,

    Can you please let me know how can I acheive this thru Business rule?

    Cheers,

    Saratha

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    try something like this. Here I am making Phone mandatory if account name contans 'Ravi'.

    MainPhonerequired.png

    Hope this helps.

  • Suggested answer
    David Yu Profile Picture
    on at

    Hi Saratha,

    If you need to use JS to check, you may use the client API setRequiredLevel.

    If you need to mark it as business required, you may us the following script.

    formContext.getAttribute("attribute_name").setRequiredLevel(required);

    For more information, please check the official document.

    docs.microsoft.com/.../setrequiredlevel

  • Poornimaa Profile Picture
    108 on at

    Hi Ravi,

    Thanks again :)

    I have done exactly like this, but it works for me after saving the form. And, we are using crm 2016.

  • RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi,

    Do you have both the fields on the formvisible/editable?

    I do not have CRM 2016 environment so can't test it but to my knowledge this should work. Can you try some simple rule to check and confirm that business rule work on form load ..say something like setting value to a field.

  • Suggested answer
    David Yu Profile Picture
    on at

    Hi Saratha,

    You may verify this field value before you save the record. JS can be attached when the form onsave. Or you may add a plugin to verify that when the record get saved.

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 83 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

#3
#ManoVerse Profile Picture

#ManoVerse 40

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans