getSCAttachmentCount() is getting error in my portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2022 02:35 AM
getSCAttachmentCount(); is not working for me. I copied same code from the community, still not working.
onSubmit Client Script code:
function onSubmit() {
try {
var attachmentList = gel("header_attachment_list_label");
if (attachmentList) {
if (attachmentList.style.visibility == "hidden" || attachmentList.style.display == "none") {
if (confirm("message")) {
return true;
} else
return false;
}
}
} catch (e) { //For Service Portal
var count = getSCAttachmentCount();
if (count <= 0) {
if (confirm("message")) {
return true;
} else
return false;
}
}
}
And I added UI script as follows:
function getSCAttachmentCount() {
var length;
try {
length = angular.element("#sc_cat_item").scope().attachments.length;
} catch (e) {
length = -1;
}
return length;
}
Still I got the error message in console like this:
Can someone help me with that.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2022 03:20 AM
Hi can you uncheck Isolate script checkbox to false save and re try?
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2022 03:24 AM
Still getting same error.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2022 03:24 AM
Replace this. I tested works good for me in PDI
function onSubmit() {
var alertWord = "Please use the paperclip icon below to attach receipts before submitting the request.";
try {
var attachments = g_form.getControl('header_attachment_list_label');
if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none' ) {
alert(alertWord);
return false;
}
} catch (e) { //For Service Portal
var count = getSCAttachmentCount();
if (count <= 0) {
alert(alertWord);
return false;
}
}
}
Harish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2022 03:27 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2022 02:41 AM
Hi,
I am not sure from where did you copied but the issue - onsubmit client script have "getSCAttachmentCount" method add the all code in onsubmit client script
Thanks
Chandu Telu
Please Mark ✅ Correct/helpful, if applicable,