Gliderecord query for the table alm_asset

Hamza Berouil2
Tera Guru

Hi all,

I am facing a weird issue (or maybe I am wrong).

I am trying to run a simple background script to retrieve field values from the tables Asset and Hardware (lets say for example install_status), but the system always return the value "undefined".

Here is my script :

  var myQuery = 'u_configurationLIKE_MANUEL';

  var gr = new GlideRecord("alm_asset");

  gr.addEncodedQuery(myQuery);

  gr.query();

  gs.print('count :'+ gr.getRowCount());

  if (gr.next()) {

  gs.print("status: "+ gr.install_status);

  }

The first "gs.print" returns 23 (what is expected) but the second returns undefined.

If I replace install_status by sys_id, it works fine !!

If I take any other field I always get "undefined" value.

I thought maybe it's due to an ACL, but when I have a look to the Asset list I can see all the fields which confirms that it's not due to an ACL issue.

If I run a similar query for any other table, it works fine.

Any idea guys ? is it something specific to Asset management ?

Thank you in advance

Best regards,

Hamza

1 ACCEPTED SOLUTION

The solution is very very simple !!!



Simply do not use "gr" as a variable name in a GlideRecord !!



Thank you guys for your help !!



Best regards,


Hamza


View solution in original post

24 REPLIES 24

All the fields i have teste are active.



Actually I have tested other fields and the result still the same


Interesting. Let's try this then... I want to see the fields and some values.



var myQuery = 'u_configurationLIKE_MANUEL';  


 


  var gr = new GlideRecord("alm_asset");  


  gr.addEncodedQuery(myQuery);  


  gr.query();  


  gs.print('count :'+ gr.getRowCount());  


  if (gr.next()) {  


      var fields = gr.getFields();



      // Enumerate GlideElements in the GlideRecord object that have values


      gs.print('Enumerating over all fields with values:');


      for (var i = 0; i < fields.size(); i++) {


          var glideElement = fields.get(i);


          if (glideElement.hasValue()) {


              gs.print('   ' + glideElement.getName() + '\t' + glideElement);


          }


      }


  }  


Thanks Chuck, here is the result:




Time: 0:00:00.207 id: ***************_1[glide.9] for: SELECT alm_asset0.`sys_id` FROM alm_asset alm_asset0 WHERE alm_asset0.`u_configuration` LIKE '%\\_MANUEL%'


*** Script: count :23


*** Script: Enumerating over all fields with values:


*** Script: record_checkpoint 19


*** Script: sys_created_by admin


*** Script: sys_created_on 2016-05-25 12:41:30


*** Script: fieldname install_status


*** Script: documentkey 568203db37429a00cd3a532e53990ebf


*** Script: tablename alm_hardware


*** Script: newvalue 6


*** Script: user admin


*** Script: oldvalue 1


*** Script: internal_checkpoint 154e7ef27490000001



Seems many fields are hidden


Interesting. Very interesting. It says tablename alm_hardware, fieldname install_status. Something is very bizarre if we're both running the same script.



What release of ServiceNow are you on?


Yeah it's really challenging



The release is Fuji