Batch functionality to approve the programs

VSN
Tera Expert

I wanted to know the possible ways and solutions on the requirement, that is 

 

I want a batch function to approve programs and underlying projects, so that users can approve multiple records at once , and proffered functionality was available in configuration workspace .

4 REPLIES 4

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @VSN 

 

But will it a good case, to approve multiple records without checking it 1-1. I can say approve via List view is still option. 

*************************************************************************************************************
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]

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

@Dr Atul G- LNG Approving via list view is only possible for Native, i don't think it works for workspace. 

my user was approving records in workspace.

Hi @VSN 

 

I think OOTB it is not available. BUt have a look here

 

https://www.servicenow.com/community/next-experience-forum/custom-workspace-add-option-on-approvers-...

 

*************************************************************************************************************
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]

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

Rajdeep Ganguly
Mega Guru


Sure, here are the possible ways and solutions to implement a batch function to approve programs and underlying projects in ServiceNow:

1. **Custom Scripted REST API**: You can create a custom Scripted REST API in ServiceNow that accepts a list of record sys_ids and the approval status. This API will iterate over the list of sys_ids, fetch the corresponding records, and update the approval status.

- Sample Code:

(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var body = request.body.data;
var gr = new GlideRecord('your_table_name');
body.records.forEach(function(record) {
if (gr.get(record.sys_id)) {
gr.u_approval = body.approval_status;
gr.update();
}
});
})();

2. **UI Action**: You can create a UI Action that appears on the list view. Users can select multiple records and click on this UI Action to approve them all at once.

- Sample Code:

var gr = new GlideRecord('your_table_name');
gr.addQuery('sys_id', 'IN', current.sys_ids);
gr.query();
while (gr.next()) {
gr.u_approval = 'approved';
gr.update();
}

3. **Flow Designer**: You can use Flow Designer to create a flow that triggers on record update. If the approval field is set to 'approved', it will update all related records to 'approved' as well.

- Steps:
- Navigate to Flow Designer.
- Create a new Flow.
- Add a trigger for 'Record Updated'.
- Add an action to update related records.
- Publish the Flow.

4. **Business Rule**: You can create a Business Rule that triggers on record update and approves all related records.

- Sample Code:

(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('your_table_name');
gr.addQuery('parent', current.sys_id);
gr.query();
while (gr.next()) {
gr.u_approval = 'approved';
gr.update();
}
})(current, previous);


Please replace 'your_table_name' with the actual table name and 'u_approval' with the actual field name in your instance.


nowKB.com

For asking ServiceNow-related questions try this :
For a better and more optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.
Link - https://nowgpt.ai/

For the ServiceNow Certified System Administrator exams try this :
https://www.udemy.com/course/servicenow-csa-admin-certification-exam-2023/?couponCode=NOW-DEVELOPER