Restrict state field on the sysapproval_approver table for approver

Avinash72
Tera Contributor

Hi All,

 

The Approver(ITIL) is able to update the state field in record for sysapproval_approver table.

The approver is changing the state from Rejected to approve and after approve to rejected and to requested also.

In order to avoid this we have to restrict the state field of approval table, so that once approver changes the values then he/she should not be able to update the state second time.

Tried with ui policy and client script but no luck.

Please give me idea and i can go for a script.

 

Regards,

Avinash

1 ACCEPTED SOLUTION

Abhay Kumar1
Giga Sage

@Avinash72 To restrict the state field of the sysapproval_approver table so that an approver cannot change the state once it's been updated, you can implement a solution that works on the server side, specifically in a Business Rule.

 

Trigger on before update, check the condition and abort transaction , pls find sample script and feel free to modify if suits with your requirement:

// To restrict Approver from changing the state field

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

    // Check if the state has been set before and is different now

    if ((previous.state == 'approved' || previous.state == 'rejected') && current.state != previous.state) {

        // Prevent the update by setting the state back to the previous value

        current.state = previous.state;    

        // Optionally, you can add an error message to inform the approver that they cannot change the state anymore

        gs.addErrorMessage('You cannot change the state once it has been updated to "Approved" or "Rejected".');

        // Prevent the save

        current.setAbortAction(true);

    }

})(current, previous);

 

Hope this will help you.

View solution in original post

3 REPLIES 3

Anand Kumar P
Giga Patron
Giga Patron

Hi @Avinash72 ,

 

You can create before update business rule on sysapproval_approver table and check current state compare to previous state thensetabortaction 

 

If my response helped, please mark it as the accepted solution and give a thumbs up👍.
Thanks,
Anand

Abhay Kumar1
Giga Sage

@Avinash72 To restrict the state field of the sysapproval_approver table so that an approver cannot change the state once it's been updated, you can implement a solution that works on the server side, specifically in a Business Rule.

 

Trigger on before update, check the condition and abort transaction , pls find sample script and feel free to modify if suits with your requirement:

// To restrict Approver from changing the state field

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

    // Check if the state has been set before and is different now

    if ((previous.state == 'approved' || previous.state == 'rejected') && current.state != previous.state) {

        // Prevent the update by setting the state back to the previous value

        current.state = previous.state;    

        // Optionally, you can add an error message to inform the approver that they cannot change the state anymore

        gs.addErrorMessage('You cannot change the state once it has been updated to "Approved" or "Rejected".');

        // Prevent the save

        current.setAbortAction(true);

    }

})(current, previous);

 

Hope this will help you.

Juhi Poddar
Kilo Patron

Hello @Avinash72 

  • Logic implemented is when the state is not requested then approver will not be able to change the state.
  • This will prevent approver to change the state once it is rejected/approved/no longer required/cancelled.

Create a Before Update business rules:

Screenshot1: BR configuration setup

JuhiPoddar_0-1733859514131.png

Screenshot2: Advanced tab in BR

JuhiPoddar_1-1733859633632.png

Business Rule Condition:

current.state != previous.state

BR Script:

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

    // Add your code here
    var approver = gs.getUserID();
	
    // Check if the current user is an approver
    if (current.approver == approver) {
        // Check if the current state is not 'Requested'
        if (previous.state != 'requested') {
            gs.addErrorMessage('You cannot change the approval state if state is ' + previous.state);
            current.setAbortAction(true); // Abort the update
        }
    }
})(current, previous);

Result:

JuhiPoddar_3-1733859956121.png

Hope this helps!

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps others find the solution more easily and supports the community!"

 

Thank You
Juhi Poddar