- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2022 12:34 AM
I wanted to prevent form submission where requested on catalog item who is having the division and subdivision is customer and support in sys_user table then that user will be able to submit the catalog item form or else not.
i tried to get this solve with the help of getReference method in onsubmit client script but it is not working.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2022 03:19 AM
Hi,
so what script did you use?
you can use onChange client script + GlideAjax
OR
you can use onSubmit with GlideAjax and custom solution for synchronous ajax call
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2022 12:41 AM
Hi
In Onsubmit client script validation won't work(means...getting some data from other tables).. only the way is you need to use Synchronous GlideAjax but it won't work on Service Portal.
So I suggest you to set reference qualifier for the "Requested on" field for the catalog item..so that it will show users only who is having division or subdivision.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2022 03:15 AM
Hi
My suggestion here will be to use an On Change Catalog Client script and not an On Submit script as it will be difficult to validate as in Service portal during submission it won't wait for a response coming from server to validate the Division and Sub Division of the user.
Create a Client Callable Script Include and use the script as below:
var getCallerDetails = Class.create();
getCallerDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDetails : function(){
var getRequester = this.getParameter('sysparm_requester');
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id',getRequester);
gr.query();
if(gr.next()){
var obj = {};
obj.DIVISION = gr.Field_Name_of_division;
obj.SUB_DIV = gr.Field_Name_of_SUB_division;
}
return JSON.stringify(obj);
},
type: 'getCallerDetails'
});
Now create an On Change Catalog Client script in your Catalog item and use the script below. This script will clear out the Requester value if Division is Customer and Sub Division is Support and make it mandatory which will not allow them to Submit the form as mentioned below:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var gaPhone = new GlideAjax('getCallerDetails');
gaPhone.addParam('sysparm_name', 'getDetails');
gaPhone.addParam('sysparm_po', newValue);
gaPhone.getXMLAnswer(_handleResponse);
function _handleResponse(response) {
var answer = response;
var parseAnswer = JSON.parse(answer);
if(parseAnswer.DIVISION == 'customer' && parseAnswer.SUB_DIV == 'support'){
g_form.clearValue('Variable Name of Requester');
g_form.setMandatory('Variable Name of requester',true);
}
g_form.setValue('Variable name', answer); //Repalce your Variable Name where you want to set the value in
}
}
If you still need to do it via On Submit Catalog Client Script which will add a bit on extra complexity but is feasible and the solution has been mentioned in below blog on how you should do it:
https://snprotips.com/blog/2018/10/19/synchronous-lite-onsubmit-catalogclient-scripts
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2022 03:19 AM
Hi,
so what script did you use?
you can use onChange client script + GlideAjax
OR
you can use onSubmit with GlideAjax and custom solution for synchronous ajax call
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2022 04:59 AM
Hello Ankur,
I am using on submit client script with getReference method using Callback function.