Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

on submit scripts on list collector

TMKAM
Tera Contributor

I would like to write a on submit catalog scripts but im not sure how to write it based on below scenario.

I have created 5 list collector variables as per below.

 1. Variable A

 2. Variable B

 3. Variable C

 4. Variable D

 5. Variable E

 

Scenario A

If any 1 of the variables below is populated the requester can add to cart or order now in service catalog

 1. Variable A (empty)

 2. Variable B (empty)

 3. Variable C (populated)

 4. Variable D (empty)

 5. Variable E (empty)

 

Scenario B

If all variables below are empty the requester can't add to cart or order now in service catalog and an alert message should prompt out that requester must populate 1 of the variables.

 1. Variable A (empty)

 2. Variable B (empty)

 3. Variable C (empty)

 4. Variable D (empty)

 5. Variable E (empty)

 

Thank you

Regards,

TMKam

1 ACCEPTED SOLUTION

Hi, it meant to be used like this. It looks like the function is missing the closure parathesis " } ".

 

 

function onSubmit() {

var a = g_form.getValue('var1');

var b = g_form.getValue('var2);

if(a || b) {

return true;
} else {
return false;
}
}

 

 

 

View solution in original post

4 REPLIES 4

Kshitij3
Tera Contributor

Hi,

 

You need to use the g_form.getValue() method to get the values of all the variables. Once you get the values put a if condition where you use OR condition to check atleast one variable has the value and then accordingly you can return true or false.

var a = g_form.getValue('var1');

var b = g_form.getValue('var2);

if(a || b){

return true;}

else {return false;}

 

Try this and let me know if this is helpful.

TMKAM
Tera Contributor

Hi k**bleep**ij3,

Thank you for sharing the solution but i have receive an error message as attach.

Regards,

TMKam

Hi, it meant to be used like this. It looks like the function is missing the closure parathesis " } ".

 

 

function onSubmit() {

var a = g_form.getValue('var1');

var b = g_form.getValue('var2);

if(a || b) {

return true;
} else {
return false;
}
}

 

 

 

TMKAM
Tera Contributor

Dear SG23,

 

Thank you for the solution and I have enhanced it as per below.

 

function onSubmit(){
 
var a = g_form.getValue('u_im_group');
 
var b = g_form.getValue('u_cm_group');
 
var c = g_form.getValue('u_catalog_group');
 
var d = g_form.getValue('u_pm_group');
 
var e = g_form.getValue('u_revoked_removed_groups');
 
if(a || b || c|| d|| e){
 
return true;
 
} else {
 
//alert('You must select 1 of the Authorization Group before submitting this request.');
alert(getMessage('You must select 1 of the Authorization Group before submitting this request.'));
 
return false;
}
}