- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2017 08:46 AM
Hi all,
We have an existing script to require an attachment upon submission which works, but we're trying to tweak the same script for a new catalog item.
The new catalog item will require an attachment upon submission if a certain field's value is "yes". Here's the script:
function onSubmit() {
try {
var attachments = document.getElementById('header_attachment_list_label');
var contract = g_form.getValue('signed_pricing_contract');
if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none' && contract == 'yes') {
alert("Please be sure to attach all required documentation prior to submitting your request");
return false;
}
} catch(e) {
if ((this.document.getElementsByClassName('get-attachment').length == 0) && contract == 'yes') {
alert('Please add the required attachment before submitting this request.');
return false;
}
}
}
The && contract == 'yes' part isn't working as expected. Can someone point out what is incorrect?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2017 09:55 AM
Hi Alexander,
Hope you are following this thread: Require attachment for catalog item in Service Portal. If so, please create a new UI Script as below and modify your existing onSumbit Catalog Client Script.
UI Script:
API Name:GlobalCatalogItemFunctions
Script:
function getSCAttachmentCount() {
var length;
try {
length = angular.element("#sc_cat_item").scope().attachments.length;
} catch(e) {
length = -1;
}
return length;
}
onSubmit Catalog Client Scrip:
function onSubmit() {
var contract = g_form.getValue('signed_pricing_contract');
if(contract == 'Yes'){
try { //Works in non-portal ui
var attachments = document.getElementById('header_attachment_list_label');
if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none' ) {
alert('Please attach atleast one attachment to proceed');
return false;
}
}
catch(e) { //For Service Portal
var count = getSCAttachmentCount();
if(count <= 0) {
alert('Please attach atleast one attachment to proceed');
return false;
}
}
}
}
Although I would like to encourage you to follow this thread along with: Script Include & Catalog Client script Working properly in GLOBAL application but doesn't work in SC...
I hope this helps. Please mark correct/helpful based on impact
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2017 10:07 AM
Perfect, got it. Thanks for the info.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2019 05:27 AM
Hi, I tried above code but I'm getting an error " Error while running Client Script "check attachment": ReferenceError: getSCAttachmentCount is not defined"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2020 12:19 AM
Make the global checkbox 'True' in the getSCAttachmentCount script include.
It worked for me!