abeyahmad / servicenow-rest

18 stars 13 forks source link

Random undefined response #1

Closed krysbzh closed 7 years ago

krysbzh commented 8 years ago

Hello, I'm currently testing the query method of GlideRecord with a demo ServiceNow instance. The server returns the good list of records but sometimes, I receive randomly a value "undefined". Do you encountered the same behavior ? If I resend the request, I receive again the good values.

Thanks in advance

abeyahmad commented 8 years ago

That hasn't happened to me but I'd like to look into it. Which method are you using in GlideRecord?

On Tue, Feb 16, 2016 at 5:38 AM, krysbzh notifications@github.com wrote:

Hello, I'm currently testing the query method of GlideRecord with a demo ServiceNow instance. The server returns the good list of records but sometimes, I receive randomly a value "undefined". Do you encountered the same behavior ? If I resend the request, I receive again the good values.

Thanks in advance

— Reply to this email directly or view it on GitHub https://github.com/abeyahmad/servicenow-rest/issues/1.

krysbzh commented 8 years ago

Sorry for the delay. Here you can see my method ` //Get list of records sn.get('/:table_name', function(req, res) { var tableName = req.params.table_name; var gr = new GlideRecord('demo003',tableName,'itil','itil');

console.log(new Date(), 'In hello route GET / req.query=', req.query);
var result;

console.log("START");

//Champs retournes
if(req.query.returnFields != undefined){
  gr.setReturnFields(req.query.returnFields);
}else{
  gr.setReturnFields('number,short_description');
}

//requete ServiceNow
if(req.query.encodedQuery != undefined){
  gr.addEncodedQuery(req.query.encodedQuery);
}else {
  gr.addEncodedQuery('active=true');
}

//limite du nombre d'enregistrements
if(req.query.limit != undefined){
  gr.setLimit(req.query.limit);
}else{
  gr.setLimit(10);
}

gr.query().then(
  function(value) {
     console.log(value);
     res.json(value);
     console.log("THE END");
  }, function(err) {
    console.log(err);
  })

}); `

Generally, the result is

req.query=' { limit: '2' } START [ { short_description: 'Unable to get to network file shares', number: 'INC0000002' }, { short_description: 'Wireless access is down in my area', number: 'INC0000003' } ] THE END

but randomly, the results is : req.query=' { limit: '2' } START undefined THE END

abeyahmad commented 7 years ago

Apparently older version of the REST API returns undefined for certains conditions. I fixed the readme to include parameter in constructor to specify version