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

Hi @Ankur Bawiskar  i have debugged now and am able to make it work with the link that Anurag mentioned . Thanks

Hi @Ankur Bawiskar 

i added the script and i noticed it is not working well in native Ui

it is popping up a message mentioning native ui wont allow window, length, span

i made isolate script as false

Please let me know how this can be resolved

else{
		// native view
         var length = $j("li.attachment_list_items").find("span").length;
		if(length != countRequired){
			alert('You must add 2 attachments before submitting this request.');
			return false;
		}
	}