Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

158
Views
Javascript in D365, set required filed

I have a requirement to set visible and set required field on chosing one option. I am able to set visible but not able to setRequiredLevel in client API.

if(selectedItemCurrent != null && selectedItemCurrent.includes(8))
                {
                     formContext.getControl("comments").setVisible(true);
                     formContext.getControl("comments").setRequiredLevel("required");
                 } else
                 {
                     formContext.getControl("comments").setVisible(false);
                     formContext.getControl("comments").setRequiredLevel("none");
                 }
                
            } 

Or

formContext.getControl("comments").setVisible(selectedItemCurrent?.includes(8)&&setRequiredLevel("required"));

Both are throwing exception. Can someone help me in this?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You mentioned you can get the visible to work, so I assume the column name is correct. Please try using the getAttribute function instead of getControl when setting the requiredLevel

You can also do something like this:

let isVisible = (selectedItemCurrent != null && selectedItemCurrent.includes(8));

formContext.getControl("comments").setVisible(isVisible);
formContext.getAttribute("comments").setRequiredLevel(isVisible ? "required" : "none");

       

I am copying the documentation links for both methods.

https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/attributes/setrequiredlevel

https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/controls/setvisible

Best regards

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!