Copy the Short description from RITM to Short Description on SCTASK

riskay123
Mega Guru

Hello,

I have a flow where I am trying to copy the content of the Short description and description fields from the RITM to the Short description and description fields on the SCTASK in flow designer. I have been able to do this when using Workflow in previous catalog items, but it doesn't seem to work the same in Flow Designer.

This is an example of the script I us on the SCTASK on the workflow. How can I best tweak this so it will work in the SCTASK on a flow?

 

EXAMPLE SCRIPT

// Update task description with RITM short description

    // For example:

 

task.short_description = current.short_description;

    if(current.cat_item == 'ddbca057973202101329f6fce053af16')// Name Change Cat Item

        {

            task.short_description = "Review user details and confirm with user - "+current.short_description;

            task.description = current.description;

}

 

Thanks in advance for any help.

8 REPLIES 8

Community Alums
Not applicable

Hi @riskay123 ,

 

The way scripts work flow designer works is bit different than workflows.

 

In you scenario you need to create a flow to copy the short description.

step 1- Create the flow

step 2- add a trigger that specifies when an SCTASK is created

step 3- add an action for Lookup Records to get the RITM. Configure it to look up records in the sc_req_item table where sys_id equals current.parent.

step 4- add a action and use the below script to copy the short description.

Script-

(function execute(inputs, outputs) {
    var task = new GlideRecord('sc_task');
    if (task.get(inputs.current.sys_id)) {
        var ritm = new GlideRecord('sc_req_item');
        if (ritm.get(task.parent)) {
            task.short_description = ritm.short_description;
            task.description = ritm.description;
            if (ritm.cat_item == 'ddbca057973202101329f6fce053af16') { // Name Change Cat Item
                task.short_description = "Review user details and confirm with user - " + ritm.short_description;
            }
            task.update();
        }
    }
})(current, previous);

Note: ensure to map the inputs to the current.sys_id correctly.

 

You might need to modify the script based on other conditions. Take a look how to get the inputs and outputs.

 

If my response has resolved your query, please consider giving it a thumbs up ‌‌ and marking it as the correct answer‌‌!


Thanks & Regards,

Sanjay Kumar

Alka_Chaudhary
Mega Sage
Mega Sage

Hello @riskay123 ,

 

You can use the "Create Record" action to create the SC task record.  Then, you need to select the table and set the parent to trigger -> requested item -> sys id using the data picker. Set the short description to "scripted" and add the below code. For the description, set it to trigger -> requested item -> Description using the data picker.

 

/*
**Access Flow/Action data using the fd_data object. Script must return a value. 
**Order number is offset by +1 in Error Handling Section.
**Available options display upon pressing "." after fd_data
**example: var shortDesc = fd_data.trigger.current.short_description;
**return shortDesc;
*/
var shortDesc = fd_data.trigger.current.short_description;
 if(current.cat_item == 'ddbca057973202101329f6fce053af16'){
    shortDesc = "Review user details and confirm with user - "+shortDesc;
}
return shortDesc;

 

Alka_Chaudhary_0-1721177664545.png

Alka_Chaudhary_1-1721177729379.png

Please mark my answer as correct and helpful if it resolves your query.

Thanks,

Alka

 

 

 

Thank you Alka for your helpful reply. I have tried following your suggestions but when I try to save the flow I get an error saying "attempting to use undefined input = 'current' from Name Change".  How do I get around this?

Undefined input error.png

Hello @riskay123 ,

Try the below updated code.

/*
**Access Flow/Action data using the fd_data object. Script must return a value. 
**Order number is offset by +1 in Error Handling Section.
**Available options display upon pressing "." after fd_data
**example: var shortDesc = fd_data.trigger.current.short_description;
**return shortDesc;
*/
var shortDesc = fd_data.trigger.current.short_description;
 if(fd_data.trigger.current.cat_item == 'ddbca057973202101329f6fce053af16'){
    shortDesc = "Review user details and confirm with user - "+shortDesc;
}
return shortDesc;

Thanks,

Alka