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

I got nothing... here's the script and output from my Fuji instance... The fact that yours is sending back a tablename (with a value of alm_hardware) is baffling me. It's like we're using two different scripts.



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);


          }


      }


  }  



*** Script: count :2816


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


*** Script: residual_date 2016-07-25


*** Script: sys_domain global


*** Script: sys_mod_count 8


*** Script: sys_domain_path /


*** Script: assigned_to 9a826bf03710200044e0bfc8bcbe5dad


*** Script: department 221f79b7c6112284005d646b76ab978c


*** Script: asset_tag P1000479


*** Script: display_name P1000479 - Apple MacBook Pro 15"


*** Script: install_status 1


*** Script: depreciation 0f21351437b03000158bbfc8bcbe5da8


*** Script: skip_sync false


*** Script: po_number PO100004


*** Script: warranty_expiration 2017-01-21


*** Script: cost_center d9d0a971c0a80a641c20b13d99a48576


*** Script: ci 0ca96c0d3790200044e0bfc8bcbe5dc3


*** Script: serial_number BQP-854-D33246-GH


*** Script: order_date 2013-11-16 07:00:00


*** Script: quantity 1


*** Script: vendor b7e9e843c0a80169009a5a485bb2a2b5


*** Script: install_date 2014-01-22 07:00:00


*** Script: pre_allocated false


*** Script: model_category 81feb9c137101000deeabfc8bcbe5dc4


*** Script: location 8201c34fac1d55eb36e59da730b7d035


*** Script: sys_created_by admin


*** Script: sys_created_on 2015-10-15 08:14:21


*** Script: delivery_date 2013-12-10 07:00:00


*** Script: company 81fdf9ebac1d55eb4cb89f136a082555


*** Script: depreciation_date 2014-01-23 07:00:00


*** Script: sys_updated_by system


*** Script: sys_class_name alm_hardware


*** Script: sys_updated_on 2016-07-25 10:52:38


*** Script: purchase_date 2013-11-29


*** Script: model d501454f1b1310002502fbcd2c071334


*** Script: assigned 2014-06-22 07:00:00


I still get the same result if I remove the addEncodedQuery line :



*** Script: count :364458


*** 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



... and that's all


I think you're going to reach out to customer support on this one. There's something bizarre that we're missing. The script output is a symptom of something I'm just not picking up on. It's probably going to be something simple like a checkbox on a dictionary entry somewhere. Without hands on the system, I'm just making guesses since I cannot reproduce the issue.



I'll be curious to know wha they say - please report back here. Sorry I didn't have a quick answer for you.


Actully I have tested to check "Allow configuration'" checkbox but still not working ...  



So I will create a /Hi ticket.



Thanks a lot Chuck


Just out of curiosity... check what happens if you run that script on the incident table. I'm curious.