Get variable from ui action in client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2023 02:08 AM
Hi, i'm trying to run a UI action that takes the variables from a requested item and opens a new request.
In the catalog item there is a variable set with a client script where I want to set the variables. I can't seem to get the variables from the UI action to the client script
my UI action (action name: rerun_request):
function onClick() {
var item = g_form.getParameter("sysparm_id");
g_navigation.open("URL/sp?id=sc_cat_item&sys_id="+item+"&sysparm_clone=true', "_blank");
gsftSubmit(null, g_form.getFormElement(), rerun_request);
}
if (typeof window == "undefined")
get_variables();
function get_variables(){
var variables = new GlideRecord('sc_item_option_mtom');
variables.addQuery('request_item', current.sys_id);
variables.query();
var variable_list = [];
while (variables.next()){
var dict = variables.sc_item_option.item_option_new;
var v = variables.request_item.variables[dict.name];
var o = {
'name' = dict.name;
'question' = dict.question_text;
'value' = v;}
if (o.value != ""){
variables_list.push(o);
}
}
gs.getSession.putClientData('variable_values', variable_list);
}
My client script
function onLoad(){
var strVariables = g_user.getClientData('variable_values') // RETURNS "UNDEFINED"
var arrVariables =JSON.parse(strVariables);
for (var i=0; i<arrVariables.length; i++)
{
var name = arrVariables[i].name;
var question= arrVariables[i].question;
var value= arrVariables[i].value;
g_form.setValue(name,question,value);
}
}
can anyone can help me get the variable "variable_list" from the UI action to the client script?
Thanks 🙂
