Get all variables on a task form via script

nickmayo
Kilo Contributor

Hey all,

I'm trying to do something that may or may not be simple.

Basically, we have mandatory fields on our Catalog Tasks for users to populate. Where we're at however, users will pass tasks between each other or try to assign them before populating the mandatory tasks. The problem we run into is once you go to a task, you can assign and save the record without filling out those mandatory tasks. I'm trying to avoid making a UI policy for every mandatory task we have that says "be non mandatory unless the task state changes to Closed Complete".

So my question is: Is there a way to grab all mandatory variables off a Catalog Task form VIA Client script? Or at least grab all variables regardless of mandatory?

Or even (hopefully?) simpler, is there a way to modify this code to grab all the variables in the map, then check if they are mandatory? If so, set them non mandatory? I've been banging my head against this for awhile and a scalable solution would be perfect so we don't have to create a new UI policy everytime we need a new variable.

function onLoad(){

    try{

          //Get the 'Variables' section

          var ve = $('variable_map').up('table');

          //Disable all elements within with a class of 'cat_item_option'

          ve.select('.cat_item_option', '.slushselectmtm', '.questionsetreference').each(function(elmt){

        //CURRENTLY this will make ALL variables read only. I would like something like the following

        //if(elmt.mandatory = true){

        //         g_form.setMandatory(false);

        //}

                elmt.disabled = true;

          });

 

    catch(e){}

}

15 REPLIES 15

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!