onSubmit Script W/in Variable Set

Kelli42
Tera Contributor

I have an onSubmit script within a single-row variable set (Applies to: Variable Set) that checks a particular variable and if there are less than two people selected, it provides an error and doesn't allow submission. That variable set is active if a particular request type is selected. However, when another request type is selected the script within that single-row variable set is still being called on when trying to submit the request and not allowing submission. Aren't the client scripts supposed to be applicable to only the variable set they're in?

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

You would need an if statement more like this:

if (g_form.getValue('request_type') == 'Group Create') {

The variable named request_type can exist within or outside of the variable set in this case.  You would also want to confirm that 'Group Create' is the value stored in that variable - if it's a select box you could have that has a choice label, but a different value.  MRVS onSubmit scripts are triggered when the Add button is clicked (the second time, inside the Add Row dialog window) and can interact with the parent form (other Catalog Item variables).

View solution in original post

5 REPLIES 5

Brad Bowman
Kilo Patron
Kilo Patron

Adding variables and/or Catalog Client Scripts, Catalog UI Policies,... to a single-row variable set is merely a way to easily re-use those components in other Catalog Items. Once you've added a variable set to a Catalog Item, any scripts or policies will become part of the item as you are experiencing.  It sounds like you could wrap this script in an if block to only run it if the request type is a certain value, or null if the other Catalog Items that this variable set is used in don't have the request type variable.

I tried having a conditional written into the script as you mention but it's not working. I am very new to scripting so it's entirely likely it's user error. lol Here's what I tried:

 

function onSubmit() {
//Sets minimum number of members to 2


if ('request_type' == 'Group Create') {

var string = g_form.getValue('group_create_members');
var array = string.split(",");
if (array.length < 2) {
alert("Members of the Group Members field contains less than 2 members");
return false;
}
}
}

 

Also, this seems to be specific to a single row variable set, correct? I have an MRVS with a similar script and it is only affecting the variable set it's in, so that appears to be the case.

Brad Bowman
Kilo Patron
Kilo Patron

You would need an if statement more like this:

if (g_form.getValue('request_type') == 'Group Create') {

The variable named request_type can exist within or outside of the variable set in this case.  You would also want to confirm that 'Group Create' is the value stored in that variable - if it's a select box you could have that has a choice label, but a different value.  MRVS onSubmit scripts are triggered when the Add button is clicked (the second time, inside the Add Row dialog window) and can interact with the parent form (other Catalog Item variables).

That did it, thank you! 

I tried an iteration of that but didn't have the correct format. I appreciate the assist!