Catalog script validate attachment Error

Khaled RAJHI
Tera Contributor

Hi community,

Could you please help me to fix the Solution for the below script (Catalog script validate attachment)

Error MessageonSubmit script error: TypeError: gel is not a function:
function () { [native code] }

 

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

   var catalogsysid = gel('sysparam_item_guid').value;
   var ga = new GlideAjax('CheckAttachment');
   ga.addParam('sysparm_name','attachmentCount');
   ga.addParam('sysparm_catalogsysid',catalogsysid);
   ga.getXMLWait();
   var attCount= ga.getAnswer();
   if (attCount<1)
   {
   alert('Please Attach your Passed Certification');
   return false;
   }
else
{
return true;
}
}
6 REPLIES 6

Hello @Khaled RAJHI 

 

Try replacing gel('sysparm_item_guid').value with g_form.getUniqueValue()

Hello @Jagadish Sanadi ,

Thank you it's working now, but the alert message is always displayed even when file is attached to the request, I mean when attachment is present, the alerte is displayed and the request is submitted, I want that alert disply only when there's no attachment 

Catalog script

 

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

   var catalogsysid = g_form.getUniqueValue('sysparam_item_guid');
   var ga = new GlideAjax('CheckAttachment');
   ga.addParam('sysparm_name','attachmentCount');
   ga.addParam('sysparm_catalogsysid',catalogsysid);
   ga.getXMLWait();
   var attCount= ga.getAnswer();
   if (attCount<1)
   {
   alert('Please Attach your Passed Certification');
   return false;
   }
else
{
return true;
}
}
 
script include
 
var CheckAttachment = Class.create();
CheckAttachment.prototype = Object.extendsObject(AbstractAjaxProcessor, {
attachmentCount : function()
{
var catalogId = this.getParameter('sysparm_catalogsysid');
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_name','sc_cart_item');
gr.addQuery('table_sys_id',catalogId);
gr.query();
var attCount = gr.getRowCount();
return attCount;
},
  type: 'CheckAttachment'
});