Restricting form submission for set of users
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2023 04:46 AM
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
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';
}
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2023 05:07 AM
Hi @sanvi
If you are using this code in onSubmit client script, it will not work as the ajax.getXML() is Async. You need to modify your code to suit onSubmit client script.
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2023 05:16 AM
@sanvi Change your onSubmit client script the one below and try testing from portal, it should work.
function onSubmit() {
if (g_scratchpad.isFormValidAjax) {
g_scratchpad.isFormValidAjax = null;
return true;
}
g_scratchpad.isFormValidAjax = false;
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(ajaxResponse) {
if (answer) {
if (answer == 'valid') {
alert("action not allowed");
g_form.addErrorMessage("action not allowed");
return false;
} else {
var actionName = g_form.getActionName();
g_scratchpad.isFormValidAjax = true;
g_form.submit(actionName);
}
}
}
Please mark my answer helpful and accept as solution if it helped 👍✔️
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2023 11:10 PM
I am getting error for this line "
g_scratchpad.isFormValidAjax = false;
onSubmit script error: ReferenceError: g_scratchpad is not defined:
function () { [native code] }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2023 11:14 PM
HI @sanvi
Are you trying to submit from Portal or Platform UI? If it platform UI we need to change the code, please let me know.
Anvesh