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

Only specific variables i.e any variables that are set to mandatory by a UI policy.



Basically I need the functionality from the pop up that prevents you from saving a record when you have mandatory variables (the following mandatory variables have not been filled in pop up) but in my script so I can read variables that are set to mandatory from a policy and not the dictionary.



I need this because we add variables frequently and making UI policies for each variable is going to take far too long.




Sent from my Verizon, Samsung Galaxy smartphone


Well you can make all the fields non-mandatory by using this in your client script. Let me know hoe it goes



Client script:


var allVariables = document.getElementById('variable_map').getElementsByTagName('item');


  for(var i = 0; i < allVariables.length; i++){


  var item = allVariables[i];


  g_form.setMandatory('variables.' + item.getAttribute('qname').toString(),false);


  }



Yes, I found that solution as well but that won't work. Take the following scenarios.



On a task I have 5 variables. 3 are mandatory by UI policy, 2 are not. If I use that solution, it'll work by making all of them not mandatory. But as soon as my condition reverses, it will make all 5 mandatory, which makes two of the variables that do not need to be mandatory, mandatory. Does that make sense?




Sent from my Verizon, Samsung Galaxy smartphone


I have not tried, but why would it make other two as mandatory? We are not using them in UI policy right?


This


  1. var allVariables = document.getElementById('variable_map').getElementsByTagName('item');  

grabs all variables regardless of state.



So this will work when setting them non-mandatory BUT when you go to set the variables BACK to mandatory, its going to set all variables to mandatory.