The Now Platform® Washington DC release is live. Watch now!

Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Show workflow stage as a variable in RITM form

Marc_See
Giga Contributor

I'd like to show the stages of a requested item on the RITM. Since I only want this to only show for this particular catalog item, I created a variable "item_stage". Whenever the stage changes, I want the RITM variable to be updated. What I tried to do is that every time the SCTASK is created, I run this script:

current.variables.item_stage = current.stage;

find_real_file.png

I'm not sure if this is the best approach or the right syntax. I can't get this to work because the field is just blank:

find_real_file.png

1 ACCEPTED SOLUTION

Wait, I've had an epiphany.  Scrap all that and create an after update business rule on sc_req_item with the Filter Condition Stage changes

find_real_file.png

You can also add certain Items to the Filter Conditions, but if this variable is not found it just won't do anything - no errors displayed, or erratic behavior.  Add this Script in the Advanced tab

(function executeRule(current, previous /*null when async*/) {

current.variables.item_stage = current.stage.getDisplayValue();
current.update();

})(current, previous);

Now the variable will be updated every time the RITM stage changes.  The workflow I'm testing with starts with a run script to set some RITM values, then an approval, a task, then another approval.  I noticed when I submitted the request the RITM stage showed Approval as it was awaiting the first approval, but the variable was empty.  This is a timing issue that I've seen before on RITM creation, so adding a 10 second Timer activity prior to the approval did the trick.

View solution in original post

12 REPLIES 12

Brad Bowman
Tera Sage
Tera Sage

Why not display the field on the RITM form?

find_real_file.png

You could add a UI Policy or Client Script (not catalog) on sc_req_item if you want to hide the field based on cat_item.

If you really want to populate a variable, this will work in your workflow script

current.variables.item_stage = current.stage.getDisplayValue();

 

Marc_See
Giga Contributor

Hi Brad,

The idea behind adding the stage as a variable is so that it shows up in the approval form as shown below:

find_real_file.png

There's multiple approval tasks in the workflow (1 in the beginning and 1 close to the end). The approver wants to know what he's approving. So we figured we can show the stage of the workflow to show the stage of fulfillment.

Since we can't really do anything on the approval form to show the RITM stage, we figured this is the next best thing we can do.

What do you think?

Yeah, a variable is probably the best way to go in that case.  did .getDisplayValue() work for you?

It does! in a way.. I hope you don't mind if I ask for more help.

So, I was planning to hide the variable, but for testing purposes, I left it visible. Anyway, upon testing, it's not showing the current stage, but actually the next:

find_real_file.png

And here's the script to set the RITM:

find_real_file.png

So I'm not sure why it's looking at the next stage that has not happened yet.