BACKGROUND SCRIPT TO UPDATE APPROVER FOR RITM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2024 09:35 PM
BACKGROUND SCRIPT TO UPDATE APPROVER FOR RITM
==================================================================
var gr=new GlideRecord('sc_req_item');
gr.addQuery('document_id', '0078dba91bcb791c7eb4979f1d4bcb8e');
gr.addQuery('approver', '1847eebadb8cd99c8e1a4b6eaa961968');
gr.query();
gr.setLimit('1');
if(gr.next()){
gr.setValue('approver','9aa95475db9ef0502e1b037dd396191e');
gr.autoSysFields(false);
gr.update();
}
The script not working. Please can someone help what to modify
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2024 09:37 PM - edited ‎01-24-2024 09:38 PM
hi @shivani18
var gr=new GlideRecord('sysapproval_approver');
gr.addQuery('document_id', '0078dba91bcb791c7eb4979f1d4bcb8e');
gr.addQuery('approver', '1847eebadb8cd99c8e1a4b6eaa961968');
gr.query();
gr.setLimit('1');
if(gr.next()){
gr.setValue('approver','9aa95475db9ef0502e1b037dd396191e');
gr.autoSysFields(false);
gr.update();
}
C |
If the provided solution meets your needs, kindly consider marking it as helpful and accepting it as the solution. This helps others who may have similar questions. |
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2024 10:46 PM - edited ‎01-24-2024 10:50 PM
Hi @shivani18
Try this :-
var ritmGr = new GlideRecord('sc_req_item');
ritmGr.addQuery('document_id', '0078dba91bcb791c7eb4979f1d4bcb8e');
ritmGr.addQuery('approver', '1847eebadb8cd99c8e1a4b6eaa961968');
ritmGr.query();
ritmGr.setLimit(1);
if (ritmGr.next()) {
ritmGr.setValue('approver', '9aa95475db9ef0502e1b037dd396191e');
ritmGr.autoSysFields(false);
ritmGr.update();
// Assuming there is a reference field 'ritm_approver' on the Requested Item (RITM) record,
// you can update it as well if needed.
var ritmSysId = ritmGr.getValue('ritm_approver');
if (ritmSysId) {
var ritmRec = new GlideRecord('sc_req_item');
if (ritmRec.get(ritmSysId)) {
ritmRec.setValue('approver', '9aa95475db9ef0502e1b037dd396191e');
ritmRec.autoSysFields(false);
ritmRec.update();
}
}
}
If my solution solved your problem please give helpful and accept solution for other user benefits.
Regards,
Suyash
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2024 02:27 AM
Hi @shivani18
You are querying on the Requested Item table though the approval records are stored in sysapproval_approver table. Please modify your script as below and it should work :
var approver=new GlideRecord('sysapproval_approver');
approver.addQuery('document_id', '0078dba91bcb791c7eb4979f1d4bcb8e'); // RITM of the sys_id. Please change accordingly
approver.addQuery('approver', '1847eebadb8cd99c8e1a4b6eaa961968'); // Sys_id of the current approver
approver.query();
if(approver.next()){
approver.setValue('approver','9aa95475db9ef0502e1b037dd396191e'); // Sys_id of the new approver
approver.autoSysFields(false);
approver.update();
}
Thanks & Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.