- 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 10:02 PM
Hey @MR1
Oopss! Seems I was missing one line.
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);
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-11-2023 04:35 PM
Can we write this script "onchange" catalog client script format?
Because the reference variable "resource_group_to_be_updated" is only visible based on another multiple-choice variable. Otherwise, the reference field is hidden.
The above script is completely blocking the submission of requests.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2023 07:17 PM - edited 12-11-2023 07:19 PM
Hi @MR1
So you can simply add an additional If statement at the beginning of the existing script.
This If condition will validate the "resource_group" variable against the four choices B, C, D and return true.
function onSubmit() {
if (g_form.getValue('variable_name') === 'B' || g_form.getValue('variable_name') === 'C' || g_form.getValue('variable_name') === 'D') {
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-11-2023 07:33 PM
Thank you for your response!
I tried your above script but it failed to validate the resource_group values.
It's submitting the request for all three B, C, D values without the manager(broke something)
The issue remains the same but something went wrong and that new condition isn't helping us.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 03:10 AM
Hi @MR1
What is the requirement (relationship) between these 2 variables resource_group_to_be_updated and resource_group?
Cheers,
Tai Vu