- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2023 01:20 AM
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 😊
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2023 09:34 AM
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;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2023 05:53 AM
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'.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2023 06:46 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2023 09:34 AM
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;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2023 01:36 PM
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 🙂