The CreatorCon Call for Content is officially open! Get started here.

Hiding Catalog Variables AFTER submitted

pwright137
Kilo Expert

HELP!!
I'm having trouble getting the show/hide functionality to work on catalog variables after the request has been submitted. THe show/hide works great when the form is being filled out but is lost after it is submitted. I've tried using the UI policy in the sc_req_item table and I've tried using client scripts during onload for the same table, bot with no success.

Any ideas??

21 REPLIES 21

pwright137
Kilo Expert

The code works fine for admin but does not work for other users. The fields on the form are editable for admin but read only for the users. Is there somethng about read only fileds that can not execute scripts on fields for users?


Hi,



Were you able to resolve this issue, I am running into same issue.


Any help would be much appreciated.



Best Regards,


NJ


Hi Namrata,



Kindly go through the below steps:


1)Client script:Hide Empty Variables// Create on table "sc_req_item"


Script:


function onLoad() {


    //Hide all empty variables using the scratchpad object passed from 'Hide Empty Variables' business rule


    if(g_scratchpad.emptyVars != ''){


          var emptyVars = g_scratchpad.emptyVars.split(',');


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


                eval("g_form.setDisplay('variables." + emptyVars[i] + "', false)");


          }


    }


}


2)BR:Hide Empty Variables// Create on table "sc_req_item"


Condition:!RP.isPopup()


Script:



//Initialize the scratchpad variable


g_scratchpad.emptyVars = '';



//Check to see if a variable pool exists


var count = 0;


for(vars in current.variable_pool){


    count++;


    break;


}



//If a variable pool exists then collect empty variable names


if(count > 0){


    var emptyVars = new Array();


    var table = current.getTableName();


    //Query for the empty variables for this record


    //Catalog item and task variables pull from 'sc_item_option_mtom' table


    if(table == 'sc_req_item' || table == 'sc_task'){


          var itemVars = new GlideRecord('sc_item_option_mtom');


          if(table == 'sc_req_item'){


                itemVars.addQuery('request_item', current.sys_id);


          }


          if(table == 'sc_task'){


                itemVars.addQuery('request_item', current.request_item.sys_id);


          }


          itemVars.addNullQuery('sc_item_option.value');


          //Exclude Label and Container variables


          itemVars.addQuery('sc_item_option.item_option_new.type', '!=', 11);


          itemVars.addQuery('sc_item_option.item_option_new.type', '!=', 19);


          itemVars.addQuery('sc_item_option.item_option_new.type', '!=', 20);


          itemVars.query();


          while(itemVars.next()){


                //Add variable names to the emptyVars array


                emptyVars.push(itemVars.sc_item_option.item_option_new.name.toString());


          }


    }


    else{


          //All other variables pulled from 'question_answer' table


          var producerVars = new GlideRecord('question_answer');


          producerVars.addQuery('table_sys_id', current.sys_id);


          producerVars.addNullQuery('value');


          //Exclude Label and Container variables


          producerVars.addQuery('question.type', '!=', 11);


          producerVars.addQuery('question.type', '!=', 19);


          producerVars.addQuery('question.type', '!=', 20);


          producerVars.query();


          while(producerVars.next()){


                //Add variable names to the emptyVars array


                emptyVars.push(producerVars.question.name.toString());


          }


    }



    //Store the result in the scratchpad


    g_scratchpad.emptyVars = emptyVars.join();


}


Pls let me know if you have any questions.



Thanks and Regards


Pradeep Sharma


Hi,



I had this code earlier but when we upgraded to Calgary this doesn't work in Calgary version.



Best Regards,


NJ


Hi Namrata,



I had an similar issue when we upgraded from "Berlin" to "Calgary"   with the script.


I have raised HI ticket and it was resolved after they applied patch fix to it.



Note:In our case values of the variables were set to null once the request was submitted.



Thanks


Pradeep Sharma