background script for stage change and add approvals in approver table.

keval3
Tera Contributor

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

 

 

3 REPLIES 3

Anil Lande
Kilo Patron

Hi,

What is the field name on your system_approval table refers to your table procurement_service (parent)?

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Hi Anil,

 

The field name is 

Approver
keval3_0-1701425592974.png

 

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();

}

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande