How to cancel approvals - if change request got (reset to new) state

thaduri sai
Tera Contributor

Hi Team,

 

We have a requirement in change request - In change request we have UI button (Reset to New).

In change we are added manuall approvals. Now the change is in Assess state waiting for approvals. Some of the groups are "Approved" and other groups are "Requested" state.

If change got (reset to new) state - The approved groups are still showing in groups approvals.

 

How can we acheive to cancel all approvals if change reset new through Ui action button.

thadurisai_0-1687274000914.png

 

Thanks,

Saikrishna

 

2 ACCEPTED SOLUTIONS

Sandeep Rajput
Tera Patron
Tera Patron

@thaduri sai Create a business rule on Change Request table as follows.

 

Screenshot 2023-06-20 at 8.58.34 PM.pngScreenshot 2023-06-20 at 8.58.53 PM.png

 

Here is the BR script.

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	var approvalRec = new GlideRecord('sysapproval_approver');
	approvalRec.addQuery('document_id',current.sys_id);
	approvalRec.query();
	while(approvalRec.next()){
		approvalRec.setValue('state','not_required');
		approvalRec.update();
	}


})(current, previous);

 

View solution in original post

@babbi @thaduri sai Update the BR as follows.

 

function executeRule(current, previous /*null when async*/) {

	// Add your code here
	var approvalRec = new GlideRecord('sysapproval_approver');
	approvalRec.addQuery('document_id',current.sys_id);
	approvalRec.query();
	while(approvalRec.next()){
		approvalRec.setValue('state','not_required');
		approvalRec.update();
	}


	var approvalGroupRec = new GlideRecord('sysapproval_group');
	approvalGroupRec.addQuery('parent',current.sys_id);
	approvalGroupRec.query();
	while(approvalGroupRec.next()){
		approvalGroupRec.setValue('approval','not_required');
		approvalGroupRec.update();
	}

})(current, previous);

Hope this helps.

View solution in original post

15 REPLIES 15

Sandeep Rajput
Tera Patron
Tera Patron

@thaduri sai Create a business rule on Change Request table as follows.

 

Screenshot 2023-06-20 at 8.58.34 PM.pngScreenshot 2023-06-20 at 8.58.53 PM.png

 

Here is the BR script.

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	var approvalRec = new GlideRecord('sysapproval_approver');
	approvalRec.addQuery('document_id',current.sys_id);
	approvalRec.query();
	while(approvalRec.next()){
		approvalRec.setValue('state','not_required');
		approvalRec.update();
	}


})(current, previous);

 

Hi @Sandeep Rajput ,

 

we have retrun above BR - But it is working for approvals only  - still its showing group approvals as approved.

babbi_0-1687334883394.png

In approvals all are cancelled this is fine.

babbi_1-1687334937378.png

 

Thanks,

saikrishna

@babbi @thaduri sai Update the BR as follows.

 

function executeRule(current, previous /*null when async*/) {

	// Add your code here
	var approvalRec = new GlideRecord('sysapproval_approver');
	approvalRec.addQuery('document_id',current.sys_id);
	approvalRec.query();
	while(approvalRec.next()){
		approvalRec.setValue('state','not_required');
		approvalRec.update();
	}


	var approvalGroupRec = new GlideRecord('sysapproval_group');
	approvalGroupRec.addQuery('parent',current.sys_id);
	approvalGroupRec.query();
	while(approvalGroupRec.next()){
		approvalGroupRec.setValue('approval','not_required');
		approvalGroupRec.update();
	}

})(current, previous);

Hope this helps.

Thank you @Sandeep Rajput