Prevent submission of a service catalog item if a boolean variable is false.

Daniel Unsworth
Tera Contributor

Hi I was hoping someone could help with an onSubmit() client script?

The script is to prevent a catalog item from being submit if a boolean variable is false with a simple alert.

 

I get the alert and the the item won't allow me to submit which is what it should do but if the variable is true then

it still behaves like it's false. The script is below. I've tried else, else if with a return true but that just cancels out the return false. Script below:

 

function onSubmit() {
//Type appropriate comment here, and begin script below
if (atgm_user == 'no') {
alert ('You cannot submit this request if you are not an ATGM user.');
return false;
}

}

 

Any help greatly appreciated 😊

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

The syntax on both looks fine.  Let's temporarily add an alert at the beginning to answer the question of what value is detected for this test case:

function onSubmit() {
    var atgm = g_form.getValue('atgm_user');
    alert(atgm);
    if (atgm == 'false') {
        alert(getMessage('You have to be an ATGM user in order to use PDMLink with CREO. You cannot submit this request if you are not an ATGM user.'));
        return false;
    }
}

 

View solution in original post

6 REPLIES 6

Brad Bowman
Kilo Patron
Kilo Patron

Hi Daniel,

Your if condition is invalid, so it is ignoring that line. atgm_user is undefined in the script, so use g_form.getValue('atgm_user') to retrieve the value of the variable.  Depending on the variable type, the value may be false or 'false' rather than 'no'.

Daniel Unsworth
Tera Contributor

Hi Brad,

 

thanks for your reply. I'm fairly new to js so forgive my ignorance 🙂

 

I tried the following but this just stopped the whole script working:

 

function onSubmit() {
//Type appropriate comment here, and begin script below

if (g_form.getValue('atgm_user') == 'false') {
alert(getMessage('You have to be an ATGM user in order to use PDMLink with CREO. You cannot submit this request if you are not an ATGM user.'));

return false;
}

}

 

---------------

function onSubmit() {
//Type appropriate comment here, and begin script below
var atgm = g_form.getValue('atgm_user');
if (atgm == 'false') {
alert(getMessage('You have to be an ATGM user in order to use PDMLink with CREO. You cannot submit this request if you are not an ATGM user.'));

return false;
}

}

 

 

I've no doubt got some syntax wrong somewhere?

Brad Bowman
Kilo Patron
Kilo Patron

The syntax on both looks fine.  Let's temporarily add an alert at the beginning to answer the question of what value is detected for this test case:

function onSubmit() {
    var atgm = g_form.getValue('atgm_user');
    alert(atgm);
    if (atgm == 'false') {
        alert(getMessage('You have to be an ATGM user in order to use PDMLink with CREO. You cannot submit this request if you are not an ATGM user.'));
        return false;
    }
}

 

Daniel Unsworth
Tera Contributor

Hi Brad,

 

thank you very much. That alert showed me the values were No/Yes so I've been able to use the below script:

 

function onSubmit() {
//var atgm = g_form.getValue('atgm_user');
if (g_form.getValue('atgm_user') == 'No') {
alert(getMessage('You have to be an ATGM user in order to use PDMLink with CREO. You cannot submit this request if you are not an ATGM user.'));
return false;
}
}

 

thanks again for your help and time 🙂