background script for stage change and add approvals in approver table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2023 02:00 AM
Hi All,
I want to right background script for stage change and add approvals in approver table.
for EX: I have custom table called procurement_service and in that table there is one field called Stage and that is read-only so we want to change stage by using BG Script. and also in related list there is one tab called System Approvals and table name is system_approval. in in that there is one field called Approved. and I want to change the Approval as well. please let me know the relevant BG Script.
Thanks & Regards
Kp

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2023 02:06 AM
Hi,
What is the field name on your system_approval table refers to your table procurement_service (parent)?
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2023 02:13 AM
Hi Anil,
The field name is

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2023 02:13 AM
You can try below logic:
Please note: I have assumed field names and backed values in below script. Use correct field names and choice values as per your configurations.
var psGr = new GlideRecord('procurement_service');
psGr.addEncodedQuery('stage=pending'); // add query as per your requirement
psGr.query();
while(psGr.next()){
var appGr = new GlideRecord('system_approval');
appGr.addQuery('parent', psGr.sys_id.toString());
appGr.query();
while(appGr.next()){
appGr.approval = 'approved'; //// set new value as per your requirment
appGr.update();
}
psGr.stage = 'approved'; // set new value as per your requirment
psGr.update();
}
Thanks
Anil Lande