I have a requirement that it should be restricting to requesting a specific catalog item. It should

Archana23
Tera Contributor

I have a requirement that it should be restricting to requesting a specific catalog item. It should prevent another person from requesting that catalog item on behalf of an excluded country site user.

If my location is Bangalore in India, it should allow to submit , if other than Bangalore in India it should not allow other person to submit the request on my behalf.

Do any of you have any ideas on how to work around this apparent loophole?

Please suggest in scripting if needed.

 

 

1 ACCEPTED SOLUTION

@Archana23 

Sure

Send Invitation my mail - rithickeswar123@gmail.com

View solution in original post

9 REPLIES 9

Eshwar Reddy
Kilo Sage

Hi @Archana23 

Using User Criteria in ServiceNow to restrict access to a catalog item based on the user's location or group is a good approach.

Please mark this response as Correct and Helpful if it helps you can mark more that one reply as accepted solution

Thanks 
Eshwar

If someone is requesting on behalf of me, In that case also it should not allow them to submit beacuse my location is other than banglore.

Eshwar Reddy
Kilo Sage

@Archana23 

You can achieve via On Submit client script as well

var rFor = g_form.getValue('requested');
if (g_scratchpad.isFormValid)
return true;

var ga = new GlideAjax('UserLocation');
ga.addParam('sysparm_name''getUserLocation');
ga.addParam('sysparm_user_sysid', rFor);
ga.getXMLAnswer(handelResponse);
return false;
 
function handelResponse(answer)
{
// Check if the requester is not from Bangalore, India
if (answer !== "Bangalore") {
 
g_form.addErrorMessage("You cannot submit a request on behalf of this user from your location.");
return false// Block form submission
}else
{
var actionName = g_form.getActionName();
g_scratchpad.isFormValid = true;
g_form.submit(actionName);//resubmitting when Form is valid.
}

}
 
script Include


 
getLocation: function() {
// Get the user Sys ID from the parameters
var userSysId = this.getParameter('sysparm_user_sys_id');
gs.log("Requested User Sys ID: " + userSysId);

// Create a GlideRecord to query the sys_user table
var userGR = new GlideRecord('sys_user');
if (userGR.get(userSysId)) {
// Retrieve and log the user's location
var userLocation = userGR.location.getDisplayValue();
gs.log("User Location: " + userLocation);
return userLocation; // Return the location value
}

// Return null if the user is not found
return null;
},

Please mark this response as Correct and Helpful if it helps you can mark more that one reply as accepted solution

Thanks 
Eshwar

Hi @Eshwar Reddy , Thank you for your response.

I have tried the above script, somehow it is not working as expected, it is allowing the other user to submit the request.