- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2025 01:08 AM - edited ‎05-12-2025 01:12 AM
Hi All,
I have a below requirement:
we have 3 networks OOG, COR and CON for the requested for's company and each network has separate group like OOG Group, COR Group and CON Group.
When the Requested for's network is CON need to send approval to CON Group, in same way based on the requested for network need to send corresponding Group approvals. I am using below script in the Approval - Group activity of the workflow.
Issue: The group approval is not triggering and it is skipping this activity through approved path and moving to the next activity.
Note: I am getting below warning message in the logs.
Please correct If I have done any mistake in the script.
Thanks in advance!!
Script used in the Approval - Group activit:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2025 01:57 AM
I will suggest to have workflow IF activity which checks if approval has to go or not
that activitiy will return 'yes' or 'no'
If it returns 'yes' then take that to Group Approval
If it returns 'no' then skip the approval and update the work notes
Workflow IF Activity
answer = ifScript()
function ifScript() {
var arr = [];
var oog = 'ae506541d7225dcf871dc849cebb35fc'; // OOG Group sys_id
var cor = 'bgskydkts71dae506541c849cebb35b9'; // COR Group sys_id
var con = '56121503875ae506541c849cebb356a'; // CON Group sys_id
var requestedFor = current.variables.requested_for;
if (requestedFor) {
var user = new GlideRecord('sys_user');
if (user.get(requestedFor)) {
var companyId = user.getValue('company');
var agency = new GlideRecord('core_company');
if (agency.get(companyId)) {
var network = agency.getValue('u_network_name');
if (network) {
network = network.toLowerCase();
gs.log("Network: " + network);
if (network == 'cor') {
arr.push(cor);
} else if (network == 'con') {
arr.push(con);
} else if (network == 'oog') {
arr.push(oog);
} else {
gs.log("Unknown network: " + network);
}
} else {
gs.log("Network is not specified for company: " + companyId);
}
} else {
gs.log("Company not found for requested_for user.");
}
} else {
gs.log("Requested for user not found.");
}
} else {
gs.log("Requested for is empty.");
}
if (arr.length > 0)
return 'yes';
else
return 'no';
}
Workflow Group Approval Activity script
answer = [];
var oog = 'ae506541d7225dcf871dc849cebb35fc'; // OOG Group sys_id
var cor = 'bgskydkts71dae506541c849cebb35b9'; // COR Group sys_id
var con = '56121503875ae506541c849cebb356a'; // CON Group sys_id
var requestedFor = current.variables.requested_for;
if (requestedFor) {
var user = new GlideRecord('sys_user');
if (user.get(requestedFor)) {
var companyId = user.getValue('company');
var agency = new GlideRecord('core_company');
if (agency.get(companyId)) {
var network = agency.getValue('u_network_name');
if (network) {
network = network.toLowerCase();
gs.log("Network: " + network);
if (network == 'cor') {
answer.push(cor);
} else if (network == 'con') {
answer.push(con);
} else if (network == 'oog') {
answer.push(oog);
} else {
gs.log("Unknown network: " + network);
}
} else {
gs.log("Network is not specified for company: " + companyId);
}
} else {
gs.log("Company not found for requested_for user.");
}
} else {
gs.log("Requested for user not found.");
}
} else {
gs.log("Requested for is empty.");
}
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2025 07:25 AM
Hi All,
Thank you for your reply!
I have changed the my script like below and removed the all the else conditions now its working fine.
I want to update the RITM work notes like "Waiting for approvals". If I try to put this code(current.work_notes = "Waiting for approvals.";
current.update();) in side the conditions it is not triggering approvals.
Please correct below script for the Work notes updating.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2025 07:30 AM
@Khaja Shaik As far as I know, you cannot modify the records inside approval script using current object.
Either you need to use GlideRecord and query the record instead of using current object or use script block.