Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Unanswered

Set a mandatory field based on a condition

Posted on by 411

Hello mates,
I hope you 're all doing well, I am facing a situation that I have never encountered before

I would like to set a field required based on a condition ? I started writing a JS code but dont know if its correct or no
My requirement is to set the field "nameofsd" as required if the field "taskproject" is equal to "finished" or "finished" and if the field "team" is equal to "Team 1" or "Team 2" or "Team3"

function setFieldrequirementasrequired(executionContext)
{
    // Getting formContext
    var formContext = executionContext.getFormContext();
    var task = formContext.getAttribute("new_taskproject").getValue();
    var team = formContext.getAttribute("new_projectteam").getValue();
    if (task == "finished" || "signed" && team= "Team1" || "Team2" || "Team3")
    {
        formContext.getAttribute("nameofsd").setRequiredLevel("required");
    }
    else
    {
        //setting Email field requirement as none.
        formContext.getAttribute("nameofsd").setRequiredLevel("none"); 
    }
}
Thanks in advance mates :) 
  • Aggie57 Profile Picture
    Aggie57 360 on at
    RE: Set a mandatory field based on a condition

    You don't need to write code to do this.  Just add a business rule, we do it frequently.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans