i am getting an error getElementsByClassName(). how can i resolve it?

asha4
Kilo Contributor

i am getting an error getElementsByClassName(). how can i resolve it?

for getting the attachments length i have used this method 

1 ACCEPTED SOLUTION

These is  a nice blog written, please refer

 

https://community.servicenow.com/community?id=community_blog&sys_id=00edd9751bb090d0ada243f6fe4bcba8 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

View solution in original post

10 REPLIES 10

Hi Asha,

Try this example and make necessary changes(like field name & table name) -

function onSubmit() {

 

    //Type appropriate comment here, and begin script below

 

var cat_id = gel('sysparm_item_guid').value;

 

var rowcount=0;

 

var s = g_form.getValue('si');

 

if((s == "Attach a file"))

 

{

var attachment = new GlideRecord("sys_attachment");

 

attachment.addQuery("table_name", "change_request");

 

attachment.addQuery("table_sys_id", cat_id);

 

attachment.query();

 

while (attachment.next()) {

 

rowcount++;

 

}

if(rowcount == 2)

 

{

 

return true;

 

}

 

else

 

{

 

alert("Please attach 2 attachments ");

 

return false;   }

 

}