The CreatorCon Call for Content is officially open! Get started here.

Users should not be able to approve their own requests

nameisnani
Mega Sage

Hello Team,

 

Can anyone suggest how to achieve this requirement?


If the approver = created by user(Requested for) then they should not be able to approve the request.

 
Please provide script and Please provide screenshots . 
 
Please provide example .
 
Already verfied this link - 
Not worked , 
 
can any one please provide script and screenshots for betterunderstanding
3 REPLIES 3

Murthy Ch
Giga Sage

Hi @nameisnani 

For which table you want to write this?
Is it request item or for every table in SN?

Can you please elaborate more?

 

Thanks,
Murthy

Its_Azar
Tera Guru
Tera Guru

Hi there @nameisnani 

 you can use a Business Rule 

  • Go to System Definition > Business Rules and click on New to create a new Business Rule.
  1. Configure the Business Rule:

 

if (current.approver == current.requested_for) {
    gs.addErrorMessage("You cannot approve your own request.");
    current.setAbortAction(true);
}

 

\This Business Rule runs before the approval is inserted or updated. It checks if the approver is the same as the requested_for user. 

 

If this helps kindly accept the answer thanks much.

☑️ If this helped, please mark it as Helpful or Accept Solution so others can find the answer too.




Kind Regards,

Mohamed Azarudeen Z

Developer @ KPMG

 Microsoft MVP (AI Services), India

Community Alums
Not applicable

Hi @nameisnani ,

I tried your problem in my PDI and it works for me 

Please create before business rule and add below code 

 

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

	// Add your code here
	if(current.approver == gs.getUserID()){
		if(current.state.changes()){
			gs.log("Here");
			gs.addErrorMessage("You can nhot approve your request")
			current.setAbortAction(true);
		}
	}

})(current, previous);

 

SarthakKashyap_0-1716832891983.png

 

Result 

SarthakKashyap_1-1716832913901.png

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak