The CreatorCon Call for Content is officially open! Get started here.

Workflow scratchpad on subflow

matt_a
Kilo Guru

Hi, I have a workflow that ultimately creates an AD account and populates with some standard user information.

2 of the AD attributes are derived from reference fields on the user record in ServiceNow.

These are location and Cost Center.

In my workflow, I add the fields to the scratchpad:

workflow.scratchpad.cost_center = current.variables.cost_center.getDisplayValue();
workflow.scratchpad.location = current.variables.location.getDisplayValue();

The workflow then adds these values as inputs into a subflow:

find_real_file.png

In the subflow, I return these values to a new scratchpad:

if (workflow.inputs.u_cost_center.toString() != '') {
	workflow.scratchpad.cost_center = workflow.inputs.cost_center.toString();
}else{
	workflow.scratchpad.cost_center = not_received;
}

if (workflow.inputs.u_location.toString() != '') {
	workflow.scratchpad.location = workflow.inputs.location.toString();
}else{
	workflow.scratchpad.location = not_received;
}

However, rather than the subflows scratchpad being populated with the displayValue of the 2 fields, its populating it with the sys_id of the values even though the original scratchpad contained the display value.

Would anyone know why this is and how I can rectify it?

 

1 ACCEPTED SOLUTION

Hi,

So to assist, I created a catalog item with a reference field, had a parent flow that set the display value to a workflow scratchpad variable, passed it to a subflow, and then checked the value in the subflow and yea...a sys_id is coming across instead.

I tried several different things in the parent flow:

  • Dot-walking to the "name" of the location
  • Using getDisplayValue()
  • Setting one scratchpad variable to the name, then passing that to a second variable and using that second variable as what is passed to the subflow

And in all of those...the sys_id still came across, haha.

So, with that said, you'll have to use a run script activity, for example, and GlideRecord to take that sys_id to retrieve the display/name value from the relevant within the subflow, and then use it that way.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

5 REPLIES 5

Allen Andreas
Administrator
Administrator

Hi,

Have you verified in the parent flow that the values aren't sys_ids? I see you're using getDisplayValue(), but just double checking if it's really there as a display value?

And have you tried to remove the toString() on it, just to double-check?

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hi @Allen Andreas 

If I look at the scratchpad in the workflow contexts, it does show the display name in the first and the sys_id in the second.

I havent tried the removal of the toString(). The process is heavily integrated with a live process when an employee is onboarded. So any changes that I make, will involve me creating users in a live environment to test if it works. So wanted to get some opinions prior to attempting any changes.

Hi,

So to assist, I created a catalog item with a reference field, had a parent flow that set the display value to a workflow scratchpad variable, passed it to a subflow, and then checked the value in the subflow and yea...a sys_id is coming across instead.

I tried several different things in the parent flow:

  • Dot-walking to the "name" of the location
  • Using getDisplayValue()
  • Setting one scratchpad variable to the name, then passing that to a second variable and using that second variable as what is passed to the subflow

And in all of those...the sys_id still came across, haha.

So, with that said, you'll have to use a run script activity, for example, and GlideRecord to take that sys_id to retrieve the display/name value from the relevant within the subflow, and then use it that way.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Many thanks @Allen Andreas . I will GlideRecord the script in the subflow to get it. Appreciate your help