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

@matthew_hughes 

Glad to know that my script worked.

Please mark my response as correct and close the thread as I answered your original question.

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

@matthew_hughes 

you can convert that date format using GlideDateTime

check these links and enhance your script

The Secrets of GlideDateTime 

Convert format of glidedatetime from YYYY-MM-DD to YYYY-MMM-DD 

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