Restricting submission of a form to managers

Community Alums
Not applicable

Hi,

 

I have a catalog item that users should only be able to submit if they are a manager of the user. I want to enable a pop-up if the opened by is not the requested for's manager to tell them they can't, and cancel submission.

 

Can anyone help me with how to go about this?

 

Many thanks

 

 

1 ACCEPTED SOLUTION

Hi @Community Alums  , please update the script as below.

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

   //Type appropriate comment here, and begin script below
	var requestedFor=g_form.getValue('requested_for');
	var loggedInUser = g_user.userID;
	var user = g_form.getReference('requested_for',doAlert);
	function doAlert(user)
	{
		var manager =user.manager;
		
	if(loggedInUser != manager)
		{
			g_form.addErrorMessage('You are not user manager so can not submit the request');
		}
	}
}

Thanks,

Pooja M

View solution in original post

8 REPLIES 8

Pooja Mallikarj
Kilo Sage

Hi,

You can add alert or Error message also if the opened by/logged in user is not Requested For's manager please find below onChange client script.

Write a catalog client script Onchange of Requested For.

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

   //Type appropriate comment here, and begin script below
	var requestedFor=g_form.getValue('requested_for');
	var loggedInUser = g_user.getUserID();
	var user = g_form.getReference('requested_for',doAlert);
	function doAlert(user)
	{
		var manager =user.manager;
		
	if(loggedInUser != manager)
		{
			g_form.addErrorMessage('You are not user manager so can not submit the request');
		}
	}
}

Thanks,

Pooja M

Community Alums
Not applicable

Thanks so much @Pooja Mallikarj, works great in the back end, but on the employee center I get a message saying there is a javascript error in my browser console?

Hi @Community Alums  , please update the script as below.

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

   //Type appropriate comment here, and begin script below
	var requestedFor=g_form.getValue('requested_for');
	var loggedInUser = g_user.userID;
	var user = g_form.getReference('requested_for',doAlert);
	function doAlert(user)
	{
		var manager =user.manager;
		
	if(loggedInUser != manager)
		{
			g_form.addErrorMessage('You are not user manager so can not submit the request');
		}
	}
}

Thanks,

Pooja M

Community Alums
Not applicable

Amazing!! Thanks so much Pooja!