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

Announcements

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 55 Super User 2026 Season 1

#2
Eugen Podkorytov Profile Picture

Eugen Podkorytov 49

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 31 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans