Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Hi Everyone, My below code is not working in the page...can someone help me with the error in the

ruthra_85
Tera Contributor
 var act = g_form.getValue('u_active');
 
    if (act == true){
        g_form.setMandatory('u_location',true);
    }
    else if(act == false){
        g_form.setMandatory('u_location',false);
    }
5 REPLIES 5

Medi C
Giga Sage
Giga Sage

Hi @ruthra_85,

is the field u_active visible on the form? Can you share the error message?!


If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.

ruthra_85
Tera Contributor

 

Hi @Medi C 

 

Thank you for your response, Actually the code is not working to me, any functions that i have written in the script is not function in the form, Please find the below attached form screen shot "u_active" available in the form

 

Kindly help to fix it 

 

Thanks

 

ruthra_85_1-1742235267949.png

 

 

 

Hi @ruthra_85, taking a look at your code, this is achievable with a UI Policy without scripting.
Could you create a UI Policy instead?


Condition: Active = true; ("Reverse if false" should be checked)

UI Policy Action: Location --> Mandatory = true
 
By this, if Active is false, Location field would no longer be mandatory.
 

If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.

ruthra_85
Tera Contributor

Sir This is Achievable in the UI policy but the expectation is to get it done in the code. I hope written the correct code but not working sir