Trying to add a script to a flow to manipulate sc_task and sc_req_item states

Jason Edinger
Tera Expert

Hello!

I've been working on converting a workflow to a flow and, long story short, I ran out of actions because of the enormity of the amount of requestable items and who is responsible for approving them. In order to minimize the amount of actions under IF statements, I was trying to consolidate on state changes. Here's what it originally looked like:

 

If SCTask state is 'closed complete', set RITM state to 'closed complete'.

If SCTask is 'closed incomplete', set ritm to 'closed incomplete'.

If SCTask is 'closed skipped', set ritm to 'closed skipped'.

 

So you can see that each yields an action. I would do this with sub flows but I cannot wrap my head around how that works, so I figured let me try a script (albeit pieced together from snippets of google searches):

 

 

var task = new GlideRecord('sc_task');
var ritm == new GlideRecord('sc_req_item');
task.query()
if (task.state == "Closed Complete"){
  ritm.state = "Closed Complete")
}
else if (task.state == "Closed Incomplete"){
  ritm.state = "Closed Incmplete")
}
else if (task.state == "Closed Skipped"){
  ritm.state = "Closed Skipped")
}

 

 

Suffice it to say when I closed the sctask, the ritm didn't similarly close. I'm not much for scripting and at this point I think it may be easier for me to just clean up the workflow (rather than trying to recreate in flow designer).

 

Anyone able to help? Thanks!

6 REPLIES 6

OlaN
Giga Sage
Giga Sage

Hi,

Was there supposed to be an image of the Flow you created? It's missing in that case.

It will surely help if you could attach images showing the overall concept to be able to help you out.

 

A few pointers anyhow.

If a Flow is growing in size, it's always a good idea to split it up in smaller, more manageable, pieces. In the Vancouver release and onward, you have an very easy way to select multiple actions, and make a subflow of them. Youtube video for reference

 

I would avoid scripts that sets the stage/state on SCTASK and/or RITM records, there is a built in way of inserting stages in the Flow that handles that. See Docs for reference

 

No, I hadn't included a picture but it's at the bottom. It's basically when an access type is requested, the RITM is opened and an SCTask assigned to a group. When the task is closed (either closed complete/incomplete/skipped), I just need the RITM to be closed with the same state as the SCTask. Stages are fine, but I don't see how setting a stage is going to help me (other than using it for SLAs, which I'm already doing).

 

If I could understand how I could get this whole if then block into a reusable subflow, then I'm probably good. I'll watch the video provided shortly. Thanks.

 

 

Task status.jpg

The Update requested item record lines (107/110/113) just set the state of the RITM to the appropriate closed option (complete, incomplete, skipped).

In this particular scenario, you could combine all your if-statements into one section, and set the RITM record based on the value of the SCTASK state. Since the only thing you want in these three is to copy the value of the state from sctask to ritm, there is no need to split it into multiple branches.

So, watching your video link, converting the if statements into 3 subflows and adding them in worked just fine.