Subflow writing work_notes and workflow info in legacy workflow

ILYA STEIN
Tera Guru

I found myself in need to amend a catalog item that uses a legacy workflow (let's call it workflow A) to trigger another legacy workflow (let's call it B) at the end. Workflow B is used by another catalog item and is fully independent. It uses two variables, which are present and are of the same type and identically named in both catalog items; it writes to workflow log and leaves important details for the user in work_notes . So I added workflow B as a step in workflow A. I can see that workflow B executes, but neither its workflow log entries nor its work notes show up anywhere. Is there a way to fix that? Perhaps a property or a group of settings that control how workflow.info and current.work_notes behave in a workflow when it's triggered as a subflow?

1 ACCEPTED SOLUTION

Update, to avoid confusing others: there was no problem with the workflow after all; only a little bug in the code, introduced by accident. Both workflows use the same table (sc_req_item) and rely on the same standardized variables, so both have access to the current record and are able to write work notes. Both log into their individual workflow contexts, i.e. Workflow A has its own context and Workflow B has its own.

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@ILYA STEIN 

are you passing some inputs to Workflow B when it's called from Workflow A?

you can pass the inputs and use that in workflow B

how are you calling the 2nd workflow? is it via script? if yes then send this as input

1) Create workflow input variable

AnkurBawiskar_0-1735191643604.png

 

2) Then send the data like this

var inc = new GlideRecord('incident');
inc.get('8d44ecd62ff56010aedd55f62799b691');
inc.short_description = 'test';
inc.update();
var wflow = new Workflow();
var wfId = wflow.getWorkflowFromName("Incident") ;

var vars= {};

// you need to set the value in the same column name u_username

vars.u_username = 'my_id_to_workflow';

wflow.startFlow (wfId, inc, inc.operation() , vars) ;

3) Then access it like this

// u_username is the column name which you need to use to access the value

gs.info("workflow value"+ workflow.inputs.u_username);

Output:

AnkurBawiskar_1-1735191643641.png

 

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

This is not what I am doing. I added the workflow B (shown below) as a step in workflow A:

ILYASTEIN_0-1735268931448.png
There is no script involved in invoking this workflow; it is self contained and relies on two standardized variables that are included in the catalog item invoking workflow A (which now also includes workflow B shown above). I see in debugger that Workflow B successfully picks up the variable values.

Now, back to my question: I can see that workflow B executes, but its

workflow.info entries don't show in workflow log and its current.work_notes entries don't appear in work notes - unlike those from workflow A. Is there a way to fix that? 

 

@ILYA STEIN 

for workflow.info did you try gs.info() and see if log came

for current.work_notes the workflow B won't know what's the current object.

If you wish to write work notes to record via workflow B then ensure you pass the record sysId and query the record in workflow B and then set work notes

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Update, to avoid confusing others: there was no problem with the workflow after all; only a little bug in the code, introduced by accident. Both workflows use the same table (sc_req_item) and rely on the same standardized variables, so both have access to the current record and are able to write work notes. Both log into their individual workflow contexts, i.e. Workflow A has its own context and Workflow B has its own.