getSCAttachmentCount() is getting error in my portal

vvr0409
Giga Contributor

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:

find_real_file.png

find_real_file.png

Can someone help me with that.

12 REPLIES 12

Mohith Devatte
Tera Sage
Tera Sage

Hello @vvr0409 ,

Did you add this UI script  as JS include in your portal record before executing the client script. If not follow below steps 

1) Type in portals

find_real_file.png

2) Open your portal record and open theme record tagged in theme column 

find_real_file.png

3) Scroll down and create a  new record under JS Includes related list 

find_real_file.png

4) After clicking on new tag your UI script like below 

find_real_file.png

Then check if your client script is working or not 

Please mark my answer correct if it helps you

 

I have added the UI script in JS includes, but still not working

Hello @vvr0409 

I think you want it to work on both native and portal view 

Make sure you selected Type as ALL in the on submit client script 

and follow this article this is a clear cut explanation for your requirement

https://community.servicenow.com/community?id=community_article&sys_id=5df1797b1b0c5050fff162c4bd4bc...

Please mark my answer correct if it helps you