- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2019 09:21 PM
Hi all,
I'm trying to use a single GlideRecord to fetch [alm_asset] records for a user that have a "ci" record with the "form_factor" field that = "Laptop". I'd like to do this in one GlideRecord as opposed to finding all the asset records for the user, and then running a 2nd GlideRecord on the [cmdb_ci_computer] table to check for the ones where Form Factor = "Laptop". But it's not working as I would expect...is there something special about [alm_asset] that prevents this? Here's the script that doesn't work, and below is the nested GlideRecord that does work, but isn't the way I'd like to do it. Anyone see my issue? thanks!
This doesn't work. Joe has 2 assets, neither is laptop, but the gs.print as shown below:
var comp = new GlideRecord('alm_asset');
comp.addQuery('assigned_to', '06186449dbb3ab40d22664904b9619ad');//my user Joe
comp.addQuery('ci.form_factor', 'Laptop');//appears to skip this line entirely...trying to dotwalk here
comp.query();
while (comp.next())
{
gs.print('Form factor is '+comp.ci.form_factor);
}
Prints:
*** Script: Form factor is Tablet
*** Script: Form factor is Desktop
_____________________________________________________
This does work...Joe has 2 assets, but neither is a laptop...so the gs.print shows "Joe doesn't have a laptop" twice, which is correct (shown below). But I don't want to use this nested GlideRecord. Is it actually ok to do it this way?
var comp = new GlideRecord('alm_asset');
comp.addQuery('assigned_to', '06186449dbb3ab40d22664904b9619ad');//my test user Joe
comp.query();
while (comp.next())
{
var formFactor = new GlideRecord('cmdb_ci_computer');
formFactor.addQuery('asset', comp.sys_id);
formFactor.addQuery('form_factor', 'Laptop');
formFactor.query();
if(formFactor.next()){
gs.print('Joe has a laptop');
}else{
gs.print("Joe doesn't have a laptop");
}
}
Prints:
*** Script: Joe doesn't have a laptop
*** Script: Joe doesn't have a laptop
Solved! Go to Solution.
- Labels:
-
Best Practices
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2019 03:40 AM
alm_asset.ci is a ref to cmdb_ci rather than cmdb_ci_computer.
if you look directly on cmdb_ci there is no form_factor field, it is on cmdb_ci_computer.
form factor is on the extended table so cannot be referenced as part of the parent.
that is why the dot walk does not work.
if you run in fix script you will see:
var comp = new GlideRecord('alm_asset');
comp.query();
while (comp.next())
{
gs.print('Form factor is '+comp.ci.form_factor);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2019 09:37 PM
You can dot talk in addQuery() function.
What's data type of form_factor field?
If this is choice list field, then please compare value of choice list and NOT label.
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2019 01:05 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2019 03:40 AM
alm_asset.ci is a ref to cmdb_ci rather than cmdb_ci_computer.
if you look directly on cmdb_ci there is no form_factor field, it is on cmdb_ci_computer.
form factor is on the extended table so cannot be referenced as part of the parent.
that is why the dot walk does not work.
if you run in fix script you will see:
var comp = new GlideRecord('alm_asset');
comp.query();
while (comp.next())
{
gs.print('Form factor is '+comp.ci.form_factor);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2019 08:25 AM
Hi GGG,
ok thanks...so you're saying I cannot dotwalk in one single GlideRecord...so looks like I need to use the nested GlideRecord method for scripting this. would you agree?