Best practice to validate “Requested for” user (VIP check) before catalog submission – Portal & Nati

nameisnani
Mega Sage
I have a Service Catalog Item where users can request to enable VIP flag for a user.
 

Requirement

Before the catalog form is submitted:

  • Check if the Requested for user is already marked as VIP
  • If yes:
    • Show a clear, user‑friendly message (preferably with the user’s name)
    • Prevent the catalog request from being submitted
  • This validation must work in:
    • Service Portal
    • Native UI

 

  • What is the recommended layer to handle this kind of pre‑submission validation?
  • Is there a preferred pattern to balance performance and data integrity?
  • Any known gotchas when validating catalog submissions in Service Portal?

 

 

PLEASE provide script for this .

 

NOTE for Partculr catalog item 

 

Requestor for field comes from variable set 

 

Requested For

  • Label: Requested for
  • Backend name:
requested_for
2 REPLIES 2

Nishant_Shelar
Mega Guru

Use a Catalog Client Script (onSubmit) + GlideAjax (server check)

  • Works in Service Portal
  • Works in Native UI
  • Prevents submission (UI level)
  • Uses server-side validation 

 

onSubmit Client Script

function onSubmit() {

var user = g_form.getValue('requested_for');

 

var ga = new GlideAjax('CheckVIPUser');
ga.addParam('sysparm_name', 'isUserVIP');
ga.addParam('sysparm_user_id', user);

ga.getXMLWait();

var response = ga.getAnswer();

if (response == 'true') {
g_form.addErrorMessage("This user is already marked as VIP.");
return false;
}

return true;
}

 

Client Callable Script Include

var CheckVIPUser = Class.create();
CheckVIPUser.prototype = Object.extendsObject(AbstractAjaxProcessor, {

isUserVIP: function() {
var userId = this.getParameter('sysparm_user_id');

var gr = new GlideRecord('sys_user');
if (gr.get(userId) && gr.vip == true) {
return 'true';
}

return 'false';
}

});

 

 

Ankur Bawiskar
Tera Patron

@nameisnani 

Better to show that catalog item to only Non VIP users and hide for VIP Users

You can create user criteria with script 

Then Add this in "Available For" related list for that item

var gr = new GlideRecord("sys_user"); gr.addQuery("sys_id", user_id); gr.addQuery("vip=false"); gr.query(); answer = gr.hasNext();

User criteria for Service Portal 

var gr = new GlideRecord("sys_user");
gr.addQuery("sys_id", user_id);
gr.addQuery("vip=false");
gr.query();
answer = gr.hasNext();

55.png

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader