GlideRecord query not working??

patricklatella
Mega Sage

hi all,

I've got an onSubmit catalog client script that is meant to prevent the submission of a catalog item if there is no attachment already attached to the form.  I'm using a script I've used before, in the other cases it works fine.  However in this catalog client script, the script is breaking on the line identified below.  The upper part of the script is checking if a certain field is empty, and if it is empty it then checks if there's an attachment...and if there is no attachment it should then throw the "alert()".   Anyone see why my var attachment = new GlideRecord('sys_attachment'); line is breaking the script?

thanks!

Here's the full script:

 

function onSubmit() {
//check first if Entry #1 fields are entered
g_form.addInfoMessage('item_number1 is '+g_form.getValue('item_number1'));
if (g_form.getValue('item_number1') != ''){
return;
}
else {
//check for attachment
g_form.addInfoMessage('item_number1 is empty');
var sys_id = gel('sysparm_item_guid').value;
g_form.addInfoMessage('hello'); //this message is being displayed
var attachment = new GlideRecord('sys_attachment'); //this line appears to breaking the script
g_form.addInfoMessage('hello2');// this message is NOT being displayed
attachment.addQuery('table_name','x_cur_erp_sm_request');
attachment.addQuery('table_sys_id',sys_id);
attachment.query();

if (!attachment.next()) {
alert ("Please attach a completed Service Delivery Request form before submitting this request if not using the available fields on the form.");
return false;
}
}

15 REPLIES 15

In my scenario I'm working on, both the catalog item (a record producer) and the catalog client script are running in a scoped app.  Now interesting to note, I have this same script already working properly in multiple other places, but it doesn't work in Service Portal. 

So I'm thinking for sure that the problem here is going to ultimately be the "gel('sysparm_item_guid').value".  And so I need a new way of doing this, I think...correct?

Is there another way to script this?  Again my goal is to prevent submission of the form without an attachment.

Try using var sysId=g_form.getParameter("sysparm_id"); in line 10 instead of gel


Please mark this response as correct or helpful if it assisted you with your question.

Hi Sanjiv, does that need to be in Global in order to work?

 

var sysId=g_form.getParameter("sysparm_id");

Ignore that. Use the below

 

Use this line instead

 

      var sysId = getParameterValue('sysparm_id');

 

 

Add this function at the bottom 

function getParameterValue(name) {

      var url = document.URL.parseQuery();

      if (url[name]) {

              return decodeURI(url[name]);

      } else {

              return;

      }

}


Please mark this response as correct or helpful if it assisted you with your question.

Did it work for you?


Please mark this response as correct or helpful if it assisted you with your question.