Approval needs to be triggered based on the option selected

suuriya
Tera Contributor

Hi Community,

 

I have a requirement, there is an approver table, and it has 2 fields namely approver and cs environment. In catalog form there is reference field refers to this table so when user selects any records then the approval needs to send to the approver name mentioned in the table.

 

ex in table for dev environment approver is surya and test environment approver is ravi so when user select dev in the field then the approval needs to send to surya.

 

How we can achieve this...note I'm modifying this in existing workflow so please do let me know script to be added for this requirement 

 

Thanks in advance

4 REPLIES 4

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @suuriya 

 

You want approval based on User or based on  Environment in catalog form?

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

HI @Dr Atul G- LNG ,

 

Approval based on environment selected in this field

suuriya_0-1709480785196.pngsuuriya_1-1709480866362.png

for example: if ca1 is selected then approval need to be triggered to x person and if ca3 is selected then approval need to be triggered to y person

Hi @suuriya 

https://www.servicenow.com/community/now-platform-blog/scripted-approvals-in-flow-designer-with-flow...

https://www.servicenow.com/community/developer-forum/how-to-trigger-approval-based-on-the-field-in-c...

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Sumanth16
Kilo Patron

Hi @suuriya ,

 

Try script like below:

 

 

 

var division = current.variables.division.getDisplayValue(); // Division value fetched from the Department table
var answer = [];
var approvalGroup = '';

// Set the appropriate approval group based on the division
switch (division) {
case 'Australia Commercial':
approvalGroup = 'Australia Commercial BCD';
break;
case 'Australia Retail':
approvalGroup = 'Australia Retail BCD';
break;
case 'Corporate Centre and Services':
approvalGroup = 'Corporate Centre and Services BCD';
break;
case 'Group Services':
approvalGroup = 'Group Services BCD';
break;
case 'Group Technology':
approvalGroup = 'Group Tech BCD';
break;
case 'Institutional':
approvalGroup = 'Institutional BCD';
break;
case 'New Zealand':
approvalGroup = 'New Zealand BCD';
break;
case 'Pacific':
approvalGroup = 'Pacific BCD';
break;
case 'Technology COO Domains':
approvalGroup = 'Technology COO Domains BCD';
break;
default:
// No matching division, handle the case if needed
break;
}

var groupSysID = '';
if(approvalGroup!=''){
var groupGR = new GlideRecord('sys_user_group');
groupGR.addQuery('name', approvalGroup);
groupGR.query();

if (groupGR.next()) {
groupSysID = groupGR.getValue('sys_id');
}
}

answer.push(groupSysID);

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!

 

Thanks & Regards,

Sumanth Meda