Script in flow designer to populate catalog task description with REQ/RITM variables

Brad Campbell
Tera Contributor

Hi all

 

We are looking to start using Flow Designer and move away from the traditional Workflow. Currently we have the following script in all of our workflows that grabs only the populated or selected variables from the REQ/RITM and populates the catalog task description with this.

 

var variables = current.variables.getElements();

var str = '';
for (var i = 0; i < variables.length; i++) {
var question = variables[i].getQuestion();
var variableLabel = question.getLabel();
var variableValue = question.getDisplayValue();
if (variableValue != '') {
str = str + variableLabel + ': ' + variableValue + '\n';
}
}

task.description = str;

 

In Flow Designer I know we can pull the variables onto the task in the standard way, but I find that quite messy when there are a great number on the request. Having a succinct version in the description works for our support and fulfilment teams.

 

I have read a couple of articles and other community posts about creating a custom action to do this, but not sure how to get started.

 

And I also am not sure what the script format should be. I tried a tweaked version of the above in the create catalog task action but unsurprisingly it errored.

 

Any help appreciated.

 

1 ACCEPTED SOLUTION

Sebastian L
Mega Sage

So for your specific requirement I would not usually do in a flow designer, as it more meant for a drag and drop mentality. But if you use the "Get Catalog Variables" you don't really get to do what you are doing here, unless you write each line for each specific variable - and I understand you don't want that! 🙂 

In theory it could be done by checking each variable in the fd_data.trigger.getcatalogVariablePosition.variable and then write the question manually, but you could also do it as below: 

 

If you re-write your script to something like this, when you set the task description, then you get your current setup: 

var id = fd_data.trigger.request_item.sys_id;  //use your own trigger here, write fd_data.trigger (and then DOT(.), and it will show you your trigger name and item. However it should be close to the same. 
var gr = new GlideRecord('sc_req_item');
    gr.get(id); //We will look up your item 
var variables = gr.variables.getElements();
//else nothing is changed
var str = '';
for (var i = 0; i < variables.length; i++) {
var question = variables[i].getQuestion();
var variableLabel = question.getLabel();
var variableValue = question.getDisplayValue();
if (variableValue != '') {
str = str + variableLabel + ': ' + variableValue + '\n';
}
}
return str;

 


Best regards,
Sebastian Laursen

View solution in original post

4 REPLIES 4

Sebastian L
Mega Sage

So for your specific requirement I would not usually do in a flow designer, as it more meant for a drag and drop mentality. But if you use the "Get Catalog Variables" you don't really get to do what you are doing here, unless you write each line for each specific variable - and I understand you don't want that! 🙂 

In theory it could be done by checking each variable in the fd_data.trigger.getcatalogVariablePosition.variable and then write the question manually, but you could also do it as below: 

 

If you re-write your script to something like this, when you set the task description, then you get your current setup: 

var id = fd_data.trigger.request_item.sys_id;  //use your own trigger here, write fd_data.trigger (and then DOT(.), and it will show you your trigger name and item. However it should be close to the same. 
var gr = new GlideRecord('sc_req_item');
    gr.get(id); //We will look up your item 
var variables = gr.variables.getElements();
//else nothing is changed
var str = '';
for (var i = 0; i < variables.length; i++) {
var question = variables[i].getQuestion();
var variableLabel = question.getLabel();
var variableValue = question.getDisplayValue();
if (variableValue != '') {
str = str + variableLabel + ': ' + variableValue + '\n';
}
}
return str;

 


Best regards,
Sebastian Laursen

Thanks for taking the time to prepare this Sebastian

 

Will try this today and post the results.

Thanks again

 

I tested and works perfectly.

did you test this using a custom action in flow designer?