Why Am I getting this Error in my GlideRecord Query: "Wrapped TypeError: Cannot read property "number" from undefined"

Chris Armstron2
Giga Expert

Hi,

I am having some difficulty figuring out why I am receiving this error, "Wrapped TypeError: Cannot read property "number" from undefined" from the following script:

answer = ifScript();

function ifScript() {

  var slaType = 'Resolution';
  var number;  

  var rec = new GlideRecord('incident');
  rec.addQuery('sys_id', rec.current.number);    //I am trying to use this to work with the current incident
  rec.addQuery('active',true);
  rec.addQuery('state','!=',1);
  rec.addQuery('u_sla_type', slaType );
  rec.query();

  if (rec.next()) {

      return 'yes';
  }else
      return 'no';
  }

 

The above query is being used within an IF statement Workflow activity.  The workflow properties are tied to the 'task_sla' table, and this IF statement is setup to pull from the 'incident' table.

Screen shot of the error:

find_real_file.png

Any assistance would be greatly appreciated!

Thanks,

Chris A.

1 ACCEPTED SOLUTION

Chris Armstron2
Giga Expert

Alrighty....after working with ServiceNow support, they were able to provide what I needed to be able to work with the current incident.  Which is:  current.task.sys_id.toString();

Here is the script:

answer = ifScript();

function ifScript() {

var slaType = 'Resolution';
var inc = current.task.sys_id.toString();   //First put it into a variable

var rec = new GlideRecord('incident');
rec.addQuery('sys_id', inc);      //Then reference the variable here, in order to get the current sys_id
rec.addQuery('active',true);
rec.addQuery('state','!=',1);
rec.addQuery('u_sla_type', slaType);
rec.addQuery('category', 'security');
rec.query();

if (rec.next()) {
return 'yes';
}else
return 'no';
}

 

 

Thanks,

Chris A.

View solution in original post

4 REPLIES 4

Abhishek Pidwa
Kilo Guru

Hi,

 

So basically your error states that the rec is not queried yet and it is undefined until rec.query() line. Try changing this to just say rec.addQuery('sys_id', current.number);  

 

Let me know if this works.

Hi Abhishek,

Really appreciate the quick reply-

I had tried that earlier, but unfortunately when I use that, it appears to continually receive a 'no' for the answer and keeps cycling thru the turnstile and Wait 1 Minute:

find_real_file.png

 

I commented out the other addQuery's in the script to see if I can get a 'yes' for an answer, but it doesn't. Maybe it is still null or undefined:

answer = ifScript();

function ifScript() {

var slaType = 'Resolution';
var number;

var rec = new GlideRecord('incident');
rec.addQuery('sys_id', current.number);
//rec.addQuery('active',true);
//rec.addQuery('state','!=',1);
//rec.addQuery('u_sla_type', slaType );
rec.query();

if (rec.next()) {

return 'yes';

}else

return 'no';

}

Chris Armstron2
Giga Expert

So the following script works, but it doesn't work:

answer = ifScript();

function ifScript() {

var slaType = 'Resolution';

var rec = new GlideRecord('incident');

   rec.orderByDesc('sys_created_on');
   rec.setLimit(1);

   rec.addQuery('active',true);
   rec.addQuery('state','!=',1);
   rec.addQuery('u_sla_type', slaType );

   rec.query();

        if (rec.next()) {

        gs.log('TESTINGIF: ' + rec.getValue('number') + ' | ' + rec.getValue('sys_id'));

        return 'yes';

        }else

        return 'no';

    }

 

What I mean by that is when I accepted the ticket, which would satisfy the Response SLA and trigger the workflow to proceed past the IF statement (for that one incident), like so:

find_real_file.png

This worked for the current incident, and I was so excited to see that...but unfortunately, it also triggered every other ticket that was out there as well, to proceed to the next steps. And every new ticket that comes in is also getting triggered, and proceeding.

After further digging into the one workflow that should have been the only one to trigger, I noticed that there are Activities from other workflows, under the 'Workflow Activity History', in that one workflow.  So its like they are cross mingling.

Or perhaps since I am using the OrderbyDesc() now, its just grabbing the same ticket every time? 

Thanks,

Chris A.

Chris Armstron2
Giga Expert

Alrighty....after working with ServiceNow support, they were able to provide what I needed to be able to work with the current incident.  Which is:  current.task.sys_id.toString();

Here is the script:

answer = ifScript();

function ifScript() {

var slaType = 'Resolution';
var inc = current.task.sys_id.toString();   //First put it into a variable

var rec = new GlideRecord('incident');
rec.addQuery('sys_id', inc);      //Then reference the variable here, in order to get the current sys_id
rec.addQuery('active',true);
rec.addQuery('state','!=',1);
rec.addQuery('u_sla_type', slaType);
rec.addQuery('category', 'security');
rec.query();

if (rec.next()) {
return 'yes';
}else
return 'no';
}

 

 

Thanks,

Chris A.