Restricting form submission for set of users

sanvi
Tera Expert

Hi All,

I have a requirement on a form when the 'Requested For' user tries submitting the form if he has records in a custom table (i.e requested for = assigned to in custom table) then the user should not be able to submit the form.

I have configured a catalog 'On submit' client script and a 'Script include' for the same. 

But here in both the scenarios the user is not able to submit. can someone pls help

1) client script

var user = g_form.getValue('requested_for_M');
var ajax = new GlideAjax('Utils');
ajax.addParam('sysparm_name', 'User');
ajax.addParam('sysparm_reqfor', user);
ajax.getXML(ajaxResponse);
return false;
}
function ajaxResponse(serverResponse){
var answer = serverResponse.responseXML.documentElement.getAttribute("answer");
alert(answer);
if(answer == 'valid'){
alert("action not allowed");
}
}
 

2)Script Include

User: function() {
var add={};
var gr = new GlideRecord('CustomTable');
var usr = this.getParameter('sysparm_reqfor');
gr.addQuery('u_assigned_to', usr);
gr.query();
if(gr.next()){
return 'valid';
}
else{
return 'invalid';
}
},

8 REPLIES 8

Hi @AnveshKumar M ,

 

I need the code working for both Portal and Platform UI.

I got this error when i tried testing from platform.

Ankur Bawiskar
Tera Patron
Tera Patron

@sanvi 

why not handle the validation using onChange + GlideAjax?

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

Hi @Ankur Bawiskar ,

 

I want this for both onChange and onSubmit.... 

I am not sure if we can restrict form submission using OnChange client script. If there is a way then please let me know.

 

@sanvi 

if the validation fails you can clear the variable and make it mandatory

in this way user cannot submit the form unless validation passes

If my response helped please mark it correct and close the thread so that it benefits future readers.

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