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

Ratnakar7
Mega Sage
Mega Sage

Hi @Khaled RAJHI ,

 

You can replace the gel function with document.getElementById. Here's the modified version of your script:

function onSubmit() {
   // Get the catalog sys_id value using document.getElementById
   var catalogsysid = document.getElementById('sysparam_item_guid').value;

   // Create a new GlideAjax object
   var ga = new GlideAjax('CheckAttachment');
   ga.addParam('sysparm_name', 'attachmentCount');
   ga.addParam('sysparm_catalogsysid', catalogsysid);
   
   // Call the server-side script synchronously
   ga.getXMLWait();

   // Get the response from the server
   var attCount = ga.getAnswer();

   // Check if attachment count is less than 1
   if (attCount < 1) {
      alert('Please Attach your Passed Certification');
      return false;
   } else {
      return true;
   }
}

 

Also, refer below similar thread:

https://www.servicenow.com/community/developer-forum/gel-sysparm-item-guid-value-is-not-working-on-s...

 

Thanks,

Ratnakar

 

I tried the new script and a new error returned

onSubmit script error: TypeError: Cannot read properties of null (reading 'getElementById'):
function () { [native code] }

Jagadish Sanadi
Kilo Sage

@Jagadish Sanadi  Same Errors !