Abhinay Erra
Giga Sage

You can write this in display business rule and then set them mandatory to false in your onload client script



var mandatory_fields=[];


var set = new GlideappVariablePoolQuestionSet();


  set.setRequestID('put your request item sys_id');


  set.load();


  var vs = set.getFlatQuestions();


  for (var i = 0; i < vs.size(); i++) {


if(vs.get(i).mandatory==true){


mandatory_feilds.push(vs.get(i).getName());


}


  }


g_scratchpad.mandataoryArray=mandatory_fields;




In your client script use this


for (i=0; i<g_scratchpad.mandatoryArray.length;i++){


g_form.setMandataory(g_scratchpad.mandatoryArray[i],false);


}


Abhinay,



This is definitely helpful but it's not grabbing the actual variables for me. It's missing a couple for me (2 drop downs and a string)



Is there any limitations with your script? For example, does it ignore variable sets?


Nope, it should have grabbed all the variables which have mandatory set to true


Ah, I have found the issue.



This only works for variables that are checked off as mandatory because its checking at display. The ones I need to change are being set to mandatory by a UI policy. Variables that are not mandatory by default will not work with this solution.



I'll see if I can re-work this to check after the UI policy.



Thanks for the help!


Ahh.. I do not think this will work with a display business rule. Since


display business rule is triggerred before a record is actually displayed.


I will recommend to use a glideajax in a client script and put the server


side script in a script include.



On Monday, July 25, 2016, nickmayo <community-no-reply@servicenow.com>