Pull catalog item variables into catalog task description

Dead Blade
Kilo Guru

I have been looking at all the different post about pulling catalog item variable into the catalog task.   Most of the post have been about pulling variables into the short.description.   I would like to pull selected variable into the DESCRIPTION of the task.

My thoughts are to have a script within the Catalog item add all the variables that I wish to apply to the DESCRIPTION into one variable.   Example var u_description = Var1 + Var2 + Var3 + ext.

Then in the Workflow apply task.description = current.variables.u_description.

With this ideology I can use one workflow, but in each catalog item I can define the variables I wish to apply to the task DESCRIPTION by adding them to u_description within the Cat Item.

Your thoughts please?   And how do I apply this script to the Catalog Item?

1 ACCEPTED SOLUTION

Can you try the below script. It is a onBefore Insert/Update business rule on Catalog task table



var keys = new Array();


var set = new GlideappVariablePoolQuestionSet();


set.setRequestID(current.request_item);


set.load();


var vs = set.getFlatQuestions();


var description =''


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


if(vs.get(i).getLabel() != '' && vs.get(i).getDisplayValue() != '' && vs.get(i).getDisplayValue() != 'false') {


description = description +vs.get(i).getLabel() + " : " + vs.get(i).getDisplayValue() + "\n";


}


}



current.description = description;



Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

24 REPLIES 24

vinothkumar
Tera Guru

Hi William,



Add the below script in the catalog task advanced script section and it will set the description by concatenating all the values.



var gr = new GlideRecord("sc_req_item");


gr.addQuery("request", current.request.sys_id);


gr.query();


while(gr.next()) {


// Get Owned Variables for Requested Item and sort by Order


var ownvar = new GlideRecord('sc_item_option_mtom');


ownvar.addQuery('request_item.number', gr.number);


ownvar.addQuery('sc_item_option.value','!=','');


ownvar.orderBy('sc_item_option.order');


ownvar.query();


var items = "Description " + "\n";


while(ownvar.next()) {


var field = ownvar.sc_item_option.item_option_new;


var fieldValue = ownvar.sc_item_option.item_option_new.name;


// Print variable name



items += field.getDisplayValue() + ": " + gr.variables[fieldValue].getDisplayValue() + "\n";


}



task.description = items;


}


Hi Vinoth, where is the Advanced Script section of the Catalog Item, I do not see that option.   I have either UI Policy or Client scripts.


HI William,



I am also referring to put it in the workflow of catalog task activity. If you want to execute this activity for only some catalog item and this workflow is shared for multiple catalog item, you can also have a check in the workflow to check only if the requested item catalog item is so and so..


Hi Vinoth, my team and I are testing this in the workflow.   So far it is not working.   We are diagnosing the gs.logs.


You need a onBefore update/insert business rule on catalog task table with below script



var gr = new GlideRecord("sc_req_item");


gr.addQuery("request", current.request_item);


gr.query();


while(gr.next()) {


// Get Owned Variables for Requested Item and sort by Order


var ownvar = new GlideRecord('sc_item_option_mtom');


ownvar.addQuery('request_item.number', gr.number);


ownvar.addQuery('sc_item_option.value','!=','');


ownvar.orderBy('sc_item_option.order');


ownvar.query();


var items = "Description " + "\n";


while(ownvar.next()) {


var field = ownvar.sc_item_option.item_option_new;


var fieldValue = ownvar.sc_item_option.item_option_new.name;


// Print variable name



items += field.getDisplayValue() + ": " + gr.variables[fieldValue].getDisplayValue() + "\n";


}


current.description = items;


}



Please mark this response as correct or helpful if it assisted you with your question.