In Flow Designer, how do I return the values of the approvers in the Worknotes of a record?

matthew_hughes
Kilo Sage

I'm working on the below flow in flow designer where I'm trying to retrieve some records in the 'sysapproval_approver' table:

matthew_hughes_0-1754999590483.png

 

I'm wanting to write the Name of the Approver field to the work notes of a record that gets created:

matthew_hughes_1-1754999691480.png

 

I'm using the below code:

var approvers = fd_data._3__look_up_records.records;
var ritmNumber = fd_data.subflow_inputs.ritm.number;

var workNotes = "RITM " + ritmNumber + " approved by:\n";

for (var i = 0; i < approvers.length; i++) {
    var name = approvers[i].approver.display_value;
    var date = approvers[i].sys_updated_on;
    workNotes += "- " + name + " on " + date + "\n";
}

return workNotes;
 
However, i'm not getting the results I need. I was just wondering if anyone knows where I'm going wrong.
 
I'm creating the flow in a scoped app.

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@matthew_hughes 

this will work

var approvers = fd_data._3__look_up_records.records;
var ritmNumber = fd_data.subflow_inputs.ritm.number;

var workNotes = "RITM " + ritmNumber + " approved by:\n";

while (approvers.next()) {
    var name = approvers.approver.getDisplayValue();
    var date = approvers.sys_updated_on;
    workNotes += "- " + name + " on " + date + "\n";
}

return workNotes;

OR Another way

1) you can create a flow variable of type String

2) then use "Set Flow Variables" flow logic to iterate over the approver records and store the details

3) then use this flow variable to set value in work notes

var ritmNumber = fd_data.subflow_inputs.ritm.number;

var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('number', ritmNumber);
ritm.query();
ritm.next();

var workNotes = "RITM " + ritmNumber + " approved by:\n";

var app = new GlideRecord('sysapproval_approver');
app.addQuery('sysapproval', ritm.sys_id);
app.addQuery('state', 'approved');
app.query();
while (app.next()) {
    var name = approvers.approver.getDisplayValue();
    var date = approvers.sys_updated_on;
    workNotes += "- " + name + " on " + date + "\n";
}
return workNotes;

AnkurBawiskar_0-1755001960543.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

View solution in original post

6 REPLIES 6

Shashank_Jain
Kilo Sage

Hello @matthew_hughes ,

 

Could you please share the complete requirements — specifically, which approvals are needed and on which table you want the work notes — so that I can test it in a PDI and provide an accurate solution?

 

Thank you!

 

 

If this works, please mark it as helpful/accepted — it keeps me motivated and helps others find solutions.
Shashank Jain

Mark Manders
Mega Patron

I haven't tried it myself, but your script states var name = approvers[i].approver.display_value;

Try it with .getDisplayValue() and see what that returns, although it could already go wrong in the var approvers part. Put some logs in your script to see what you get for 'approvers'. I am wondering if that really is an array. 
Personally, I would do a 'for each' on the look up records and set a flow variable to get everything in there and then add that variable to the work notes. You will be sure to do it for each records, without having to guess if your look up records is returning the records, or sysids or something else, making your for loop return nothing.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Ankur Bawiskar
Tera Patron
Tera Patron

@matthew_hughes 

this will work

var approvers = fd_data._3__look_up_records.records;
var ritmNumber = fd_data.subflow_inputs.ritm.number;

var workNotes = "RITM " + ritmNumber + " approved by:\n";

while (approvers.next()) {
    var name = approvers.approver.getDisplayValue();
    var date = approvers.sys_updated_on;
    workNotes += "- " + name + " on " + date + "\n";
}

return workNotes;

OR Another way

1) you can create a flow variable of type String

2) then use "Set Flow Variables" flow logic to iterate over the approver records and store the details

3) then use this flow variable to set value in work notes

var ritmNumber = fd_data.subflow_inputs.ritm.number;

var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('number', ritmNumber);
ritm.query();
ritm.next();

var workNotes = "RITM " + ritmNumber + " approved by:\n";

var app = new GlideRecord('sysapproval_approver');
app.addQuery('sysapproval', ritm.sys_id);
app.addQuery('state', 'approved');
app.query();
while (app.next()) {
    var name = approvers.approver.getDisplayValue();
    var date = approvers.sys_updated_on;
    workNotes += "- " + name + " on " + date + "\n";
}
return workNotes;

AnkurBawiskar_0-1755001960543.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

Hi @Ankur Bawiskar That works great thanks. However, it shows the date as:

2025-08-12 13:22:46

 

How do I update it so that it's shown as:

12-08-2025 13:22:46