Passing scratchpad sysID of task to subflow for Requested Items WF's

tricial
Giga Contributor

I have a Workflow that create and Incident, I have 3 subflows that are creating tasks for different processes.

Is it possible at all to get the Incident sysID from the scratchpad in the main workflow to the Subflow tasks and have the incident_task reference the incident created in the main workflow.

Main WF create an incident

Subflows create incident_tasks 

I need to set the Incident on the incident_tasks.

How can I achieve this

1 ACCEPTED SOLUTION

Mark Roethof
Tera Patron
Tera Patron

Hi there,

In short, you want to retrieve the sys_id of the just generated incident? And pass that into your subflows? Is that possbile: Yes.

First, after the gr.insert(), on your GlideRecord query to generate the incident, you have gr.getUniqueValue() available. This will be the incident sys_id. You can then add to a Run Script step something like:

workflow.scratchpad.incident_sysid = gr.getUniqueValue();

On the sub-workflow, you can add Inputs. Below an production example we have. You just need something like ${workflow.scratchpad.incident_sysid}

find_real_file.png

When dragging/dropping the sub-workflow, onto your main workflow canvas, the default value will already be set. Meaning: the incident sys_id.

Within your sub-workflow, you now have the availability of the incident sys_id! Within a Run script step you could now simply use:

workflow.scratchpad.incident_sysid

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

View solution in original post

9 REPLIES 9

Mark Roethof
Tera Patron
Tera Patron

Hi there,

In short, you want to retrieve the sys_id of the just generated incident? And pass that into your subflows? Is that possbile: Yes.

First, after the gr.insert(), on your GlideRecord query to generate the incident, you have gr.getUniqueValue() available. This will be the incident sys_id. You can then add to a Run Script step something like:

workflow.scratchpad.incident_sysid = gr.getUniqueValue();

On the sub-workflow, you can add Inputs. Below an production example we have. You just need something like ${workflow.scratchpad.incident_sysid}

find_real_file.png

When dragging/dropping the sub-workflow, onto your main workflow canvas, the default value will already be set. Meaning: the incident sys_id.

Within your sub-workflow, you now have the availability of the incident sys_id! Within a Run script step you could now simply use:

workflow.scratchpad.incident_sysid

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Thank you Mark, Since Both WF and Subflow are on the Requested Items table I do not have inputs.

DO I need to make my SubFlows on the incident_task table instead?

Yes and No 🙂

The inputs is just hidden on sc_req_item table. Actually, it does work! Simply, temporarily, switch to another table, like incident and the inputs are visible. Then add your inputs 🙂 And switch the table back.
(or just disable the ui policy)

A proven mechanism, we have this in our production environment.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

I am not using a run script to create the incident, I am using the create task activity.

I am setting my workflow.scratchpad.inc = task.sys_id;

I create an input variable called Incident as a string and a default ${workflow.scratchpad.inc}

In my subflow I have a create task activity that I am using and trying to set the task.incident = workflow.scratchpad.inc

 

It works if I use 1 WF but I tried the above steps and it is not setting the incident tasks Incident when the task gets created.

SO WF has a create task activity on the incident table

workflow.scratchpad.inc = task.sys_id; I am capturing the Incident sysID

My Subflow input

Incident - string default ${workflow.scratchpad.inc}

My SubFlow Create task activity is on the incident_task table

I am setting task.incident = workflow.scratchpad.inc;

 

I am not able to get it working.

The incident does not get set with the task.

task.incident = workflow.scratchpad.inc;