Approval Script Getter Error
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2025 09:38 AM - edited 01-17-2025 09:50 AM
Friends, Where is my error?
answer = [];
var approvalGroupId = current.variables.site_or_library.u_application_owner_approval_group.sys_id.toString();
gs.info('### approvalGroupId is ' + approvalGroupId);
var approvalGroupName = current.variables.site_or_library.u_application_owner_approval_group.getDisplayValue();
gs.info('### approvalGroupName is ' + approvalGroupName);
var createdUser = current.sys_created_by;
gs.info('### createdUser is ' + createdUser);
var openedUser = current.opened_by;
gs.info('### openedUser is ' + openedUser);
var requestedUser = current.variables.vset_user;
gs.info('### requestedUser is ' + requestedUser);
var create = gs.getUser().getUserByID(createdUser).isMemberOf(approvalGroupName);
gs.info('### Created By isMember ' + create);
var open = gs.getUser().getUserByID(openedUser).isMemberOf(approvalGroupName);
gs.info('### Opened By isMember ' + open);
var request = gs.getUser().getUserByID(requestedUser).isMemberOf(approvalGroupName);
gs.info('### Requested By isMember ' + request);
if (create || open || request) {
current.work_notes = 'The Requester, person Creating, or person Opening this request is an approver of this item. Hence, the Owner Approval is skipped.';
answer.push();
}
else {
answer.push(current.variables.site_or_library.u_application_owner_approval_group.sys_id.toString());
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2025 09:43 AM
I suggest you post more context, such as where does your code reside? What are steps-to-reproduce? Once more context is provided, you will get responses that can assist you with your problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2025 10:02 AM
It is an approval script from a workflow approval activity.
- Variable
- vset_user. Reference variable to sys_user.
- site_or_library.u_application_owner_approval_group. Dot walked reference to sys_user_group as field on a CI class record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2025 10:32 AM
So what are you expecting and where does it break?
Only thing I would recommend is to use the getValue function when getting info off the current variable.
var createdUser = current.getValue('sys_created_by');
gs.info('### createdUser is ' + createdUser);
var openedUser = current.getValue('opened_by');
gs.info('### openedUser is ' + openedUser);likely something similar for your vset_user
var requestedUser = current.variables.vset_user.toString();
gs.info('### requestedUser is ' + requestedUser);
HTH & Good Luck
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2025 07:23 PM
can you explain along with screenshots what's your business requirement?
Seems it's an approval activity script so which user and group should be set for approval?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
