- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2023 09:40 PM
Hi All,
Please validate my script, I am using the catalog client script 'onSubmit' to abort the submission on the service portal. If the reference variable "Resource group" manager is empty.
The Resource Group is a referring group table(sys_user_group)
function onSubmit() {
//{
var business = g_form.getReference('resource_group_to_be_updated', getValue);
//}
alert('test1');
function getValue(business) {
// if(g_form.getValue('resource_group_manager') == '')
if(business.manager.toString() == '')
// var user = g_form.getDisplayVaue('resource_group_manager');
alert('Order Now is disabled if the assignment group manager is empty');
return false;
}
}
The user can submit the request. if the reference field is empty then abort the submission.
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 07:35 AM
Hi @MR1
So the If Statement should be the opposite. If resource_group is A then return true (we don't validate anything)
function onSubmit() {
if (g_form.getValue('resouce_group') === 'A') {
return true;
}
/*** Pop this gem into your script! */
if (g_scratchpad.isFormValid) {
return true;
}
var actionName = g_form.getActionName();
var business = g_form.getReference('resource_group_to_be_updated', getValue);
return false; //this line was missing
function getValue(business) {
if (business.manager.toString() == '') {
alert('Order Now is disabled if the assignment group manager is empty');
return false;
}
g_scratchpad.isFormValid = true;
g_form.submit(actionName);
}
}
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2023 09:46 PM
so is it going inside the callback method? what alert came?
why not have reference qualifier on that variable resource_group_to_be_updated to show only those groups where manager is not empty?
That would be much better to handle the requirement rather than allowing the user to select the group and stop the form submission
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2023 09:55 PM
Because we wanted to check if the Group manager is empty or not.
We don't want the user to submit the request with an empty group manager. Therefore, we are not using conditions on the reference qualifier variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2023 09:46 PM
Hi @MR1
If a callback function is present, this routine runs asynchronously. And it will allow user to submit before coming to the return false line.
Let's try to adjust as following below.
function onSubmit() {
/*** Pop this gem into your script! */
if (g_scratchpad.isFormValid) {
return true;
}
var actionName = g_form.getActionName();
var business = g_form.getReference('resource_group_to_be_updated', getValue);
function getValue(business) {
if (business.manager.toString() == '') {
alert('Order Now is disabled if the assignment group manager is empty');
return false;
}
g_scratchpad.isFormValid = true;
g_form.submit(actionName);
}
}
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2023 09:53 PM
Thanks for your quick response!
I tried your script but it failed and the user can submit the request.