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

Hi Sharique, what am I doing wrong?



Could not save record because of a compile error: JavaScript parse error at line (1) column (64) problem = missing ; before statement (<refname>; line 1)



task.description = current.variables.u_description +"\n1"current.variables.u_cube_office + "\n2" + current.variables.u_startdate;


William,



As you told earlier that you would not be using workflow and want to accomplish using client script then


use below code "on Submit":


current.description = current.variables.u_description +"\n"current.variables.u_cube_office + "\n" + current.variables.u_startdate;




"\n" - this is used to move the variable to next line


Could not save record because of a compile error: JavaScript parse error at line (3) column (70) problem = missing ; before statement (<refname>; line 3)


Missing semicolon


Expected an assignment or function call and instead saw an expression




function onSubmit() {


    //Type appropriate comment here, and begin script below


    current.description = current.variables.u_description +"\n"current.variables.u_cube_office + "\n" + current.variables.u_startdate;


}


oops my mistake.



Note: Before creating client script create a variable called description under the catalog item.


In the catalog client script select the catalog Item and in the variable name field select description field



Example Screen shot:



find_real_file.png



Try using this:


function onSubmit() {


    //Type appropriate comment here, and begin script below


          var desc = g_form.getValue('u_description') +"\n"+ g_form.getValue('u_cube_office') + "\n" + g_form.getValue('u_startdate');


        g_form.setValue('description',desc);


}


Thank you for your help as well.