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

Hi @Archana23 

I just updated my script. Please try the client script again and check that the field names are correct. Additionally, I've added an alert to see what values are being returned from the script.

 

@Eshwar Reddy ,

Null is coming in alert.

 

Archana23_0-1727264732799.png

 

Hi @Archana23 

Try Below Client script
its working fine for me 

 

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

@Eshwar Reddy , Can we please connect for few minutes if you are available.

@Archana23 

Sure

Send Invitation my mail - rithickeswar123@gmail.com