- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2024 10:19 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2024 11:35 AM
@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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2024 10:33 AM - edited 12-10-2024 10:43 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2024 11:35 AM
@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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2024 11:47 AM
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
Screenshot2: Advanced tab in BR
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:
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