
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2019 08:20 AM
Hi all,
I have been looking to write an OnChange client script to make an attachment mandatory when a specific variable has changed. I don't want to use the onSubmit function.
I also don't want to enable 'Add Attachment' mandatory on the catalog item itself, only when a variable has been changed.
For example: When 'Supplier Updates' is selected, a new mandatory selectbox appears, if 'Address' is then selected from the next selectbox, another mandatory selectbox appears, if Remit is selected, this is where an attachment becomes mandatory.
I am not sure how to enable this in the onChange client script. Does anyone have any crafty ideas to make this dream a reality? Thanks!!
Solved! Go to Solution.
- Labels:
-
Service Portal Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2019 10:08 AM
Now corrected!
//catalog client script to check for attachement
function onSubmit() {
if((g_form.getValue('<variable name>') == 'yes') && this.document.getElementsByClassName('get-attachment').length == 0) {
g_form.addErrorMessage(getMessage('attachment_is_mandatory'));
return false;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2019 09:21 AM
While this script is onSubmit, it should be able to be modified to an onChange; just modify the getValue to be the variable and value you want as the trigger.
//catalog client script to check for attachement
function onSubmit() {
if(g_form.getValue('<variable name>') == 'yes') && this.document.getElementsByClassName('get-attachment').length == 0) {
g_form.addErrorMessage(getMessage('attachment_is_mandatory'));
return false;
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2019 09:49 AM
Thank you very much Ian, looks like it's super close, but getting errors on the script:
function onChange() {
if(g_form.getValue('please_select_one_supplier_address') == 'remit') && this.document.getElementsByClassName('get-attachment').length == 0) {
g_form.addErrorMessage(getMessage('attachment_is_mandatory'));
return false;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2019 09:54 AM
I noticed that I have a typo on the IF line; missing parenthesis. Trying to figure out where it's missing from.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2019 10:08 AM
Now corrected!
//catalog client script to check for attachement
function onSubmit() {
if((g_form.getValue('<variable name>') == 'yes') && this.document.getElementsByClassName('get-attachment').length == 0) {
g_form.addErrorMessage(getMessage('attachment_is_mandatory'));
return false;
}
}