Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Check attachment count using on submit client script

RudhraKAM
Tera Guru

I have a requirement where i need to check if the catalog item have 2 attachments , if not it should not submit , 

i am able to check the attachment by using on submit client script on the catalog item but how and where to include the count ?

Can some one help me with that 

 

 

 

 

function onSubmit() {
//Type appropriate comment here, and begin script below

var proof = gel('sysparm_item_guid').value;
var att = new GlideRecord("sys_attachment");
att.addQuery("table_name", "sc_cart_item");
att.addQuery("table_sys_id", proof );
att.query(att);
if (!att.next()) {
alert("Please include the attachments");
return false;
}
return true;
}

1 ACCEPTED SOLUTION

Shashikant Yada
Tera Guru

You can try with this code:

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

var rowcount=0;
var attachment = new GlideRecord("sys_attachment");
attachment.addQuery("table_name", "sc_cart_item");
attachment.addQuery("table_sys_id", proof);
attachment.query();
while (attachment.next()) {
rowcount++;
}
//alert("Row "+rowcount);
if(rowcount <= 2)
{
alert("message");
return false; 
}
else
{
return true; }
}

https://community.servicenow.com/community?id=community_question&sys_id=cd49c325db5cdbc01dcaf3231f961992

Thanks
Shashikant

Hit Helpful or Correct on the impact of response.

View solution in original post

10 REPLIES 10

Hi @Mike Patel ,

In the above reply, Where is the definition of this  "getSCAttachmentCount()  ??

Shashikant Yada
Tera Guru

You can try with this code:

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

var rowcount=0;
var attachment = new GlideRecord("sys_attachment");
attachment.addQuery("table_name", "sc_cart_item");
attachment.addQuery("table_sys_id", proof);
attachment.query();
while (attachment.next()) {
rowcount++;
}
//alert("Row "+rowcount);
if(rowcount <= 2)
{
alert("message");
return false; 
}
else
{
return true; }
}

https://community.servicenow.com/community?id=community_question&sys_id=cd49c325db5cdbc01dcaf3231f961992

Thanks
Shashikant

Hit Helpful or Correct on the impact of response.

Thanks Yadav

this line: 

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

 

is not working for me, why so? I'm applying it to a record producer and to my understanding gel('sysparm_item_guid').value refers to current CART item in the order guide, where CART means it is being used for a catalog item rather thatn a record producer