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 10:02 PM
Hi there,
The script basically looks fine. Though 2 remakers:
- The table is incorrect, a spelling error. Should be: sysapproval_approver
- You are using a hardcoded sys_id for the approver. Maybe for your use case you only have one specific approver. Though can you make this dynamically? For example, if it might be a manager of a certain group? Then query for that, instead of hardcoded sys_id.
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 10:24 PM
Hi
So, what in fact is your question?
Do you want to know, how to get the sysid of any given user?
Because there is just the way to "hard code" the user, if you need a specific one (whether by SysID or name to search for the SysID).
If you have the given user in some field, let me know in which one...
So, can you describe in a bit more detail, what your question is in fact?
BR
Dirk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2020 11:34 PM