onsubmit client script is not working for attachments in scoped app

Renu9
Tera Contributor

Hi All,

I am having an attachment in record producer in scoped application. It should not allow  more than 1 attachment on submit. Below is the code. But the rowcount is always showing as 0. Please help here

 

function onSubmit() {
   
   var proof=g_form.getUniqueValue();  //sys id is displaying
   //var proof = gel('sysparm_item_guid').value;
   alert("proof is " +proof);
   var rowcount=0;
   var attachment = new GlideRecord("sys_attachment");
   attachment.addQuery("table_name", "my table name of record producer");
   attachment.addQuery("table_sys_id", proof);
   attachment.query();
   while(attachment.next())
   {
    rowcount++;
   }
   alert("row count is " +rowcount);   //0 is coming everytime
   if(rowcount >1)
   {
    alert("more than 1 attachment");
    return false;
   }
   else if(rowcount ==1){
    alert("pass");
    return true;
   }
}
 
@Ankur Bawiskar  Please guide 
1 ACCEPTED SOLUTION

Anurag Tripathi
Mega Patron
Mega Patron

Hi Renu,

 

Check this blog form Ankur that shows how to validate Attachments on catalog items, same would work for Record producer as well.

Verify Mandatory Attachments Count on Catalog Item - ServiceNow Community

 

-Anurag

View solution in original post

6 REPLIES 6

Anurag Tripathi
Mega Patron
Mega Patron

Hi Renu,

 

Check this blog form Ankur that shows how to validate Attachments on catalog items, same would work for Record producer as well.

Verify Mandatory Attachments Count on Catalog Item - ServiceNow Community

 

-Anurag

Hi @Anurag Tripathi  

I tried now, but it is not working in my case. Even though adding 2 attachments resulting false.

Renu9_0-1713258850848.png

Adding attachments over here and not the oob icon

Renu9
Tera Contributor

Hi @Ankur Bawiskar 

i am having a custom attachment drag and dropp in record producer . I want it to allow only 1 attachment more than 1 it shouldnt allow. Above is the script can u pls guide what im missing here

@Renu9 

GlideRecord won't work in client side.

the link which Anurag has shared which talks about how to validate should work fine.

Did you debug?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader