Check if User Already Approved in Workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2020 06:53 PM
In my approval workflow I need to check to see if the approval has already approved (they may have been a part of a group that has approved in an earlier step). Seems like this would be pretty straight forward but I can't get it to work.
Created an if condition in my workflow and was trying to lookup the sysapproval record to see if said user has already approved. (Not sure how to find the user so for now I hard coded it). Any suggestions. Below is what I tried (I'm guessing I don't have the sys_id). This is on a workflow that is on insert of my record.
function ifScript() {
var gr = new GlideRecord('sysapproval_approval');
gr.addQuery('sysapproval',current.sys_id);
gr.addQuery('approver','20d5bfa64fdf46007e2f0ad14210c7ed');
gr.addQuery('state','approved');
gr.query();
if(gr.next()) {
return 'yes';
} else {return 'no';}
}
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2020 07:10 PM
Try this
function ifScript() {
var gr = new GlideRecord('sysapproval_approval');
gr.addQuery('document_id',current.sys_id);
gr.addQuery('approver','20d5bfa64fdf46007e2f0ad14210c7ed');
gr.addQuery('state','approved');
gr.query();
if(gr.next()) {
return 'yes';
} else {return 'no';}
}
Please mark this correct & helpful if it answered your question.
Thanks & Regards,
Sharjeel
Muhammad

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2020 10:04 PM
You can use both sysapproval and document_id fields. Though, the table name is not correct. Slight typo. Should be: sysapproval_approver
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2020 08:26 PM
Hi,
I thought you don't need to write script for your use case it is simply possible by using if Activity condition and set Values activity. Check below Screenshot to more understanding.
Use If Activity before Approval activity and also used Set Values activity after the Approval Activity
Check If condition in below screenshot:
And check Set Value Activity :-
Please Mark Correct/Helpful answer if it help you in any way.
Thanks and Regards,
Kunal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2020 11:34 PM