- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2023 01:19 AM
Hello Experts,
I have created below reference qualifier for the alm_asset table but the reference qualifier is not working I have attached a screenshot of it Please guide why it's not working.
thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2023 02:33 AM - edited 12-21-2023 01:25 AM
Hello @Mark Wood
You can also use the script include and call that script include inside the variable in reference qualifier.
You can refer the below code:
Script Include:
var AssetFilterUtil = Class.create();
AssetFilterUtil.prototype = {
initialize: function() {},
getFilteredAssets: function() {
var requestedFor = current.variables.requested_for;
gs.log("REQ FOR - " + requestedFor);
var assetIds = [];
var arrayUtil = new ArrayUtil();
var assetGr = new GlideRecord('alm_asset');
assetGr.addQuery('assigned_to', requestedFor);
// assetGr.addEncodedQuery('sys_class_name=alm_hardware^ORsys_class_name=alm_consumable^install_statusNOT IN7');
assetGr.addQuery('sys_class_name', 'IN', ['alm_hardware', 'alm_consumable']);
assetGr.addQuery('install_status', 'NOT IN', [7, 8]);
assetGr.addQuery('state', 'NOT', 'retired');
assetGr.query();
while (assetGr.next()) {
gs.log("Inside while");
assetIds.push(assetGr.sys_id.toString());
}
return 'sys_idIN' + arrayUtil.unique(assetIds).join(',');
},
type: 'AssetFilterUtil'
};
Reference Qualifier:
javascript: new AssetFilterUtil(). getFilteredAssets();
Let me know your views on this and Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Regards,
Aniket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2023 01:44 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2023 01:50 AM
I want to show only one asset record there which is showing in the current assigned hardware variable. same result I want to show in a select asset for the replacement variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2023 02:27 AM
Your ref qual query looks to be failing. How many assets does George have assigned to him? Seems like he has a lot of monitors from the scroll bar in the picture.
Looking at your script you had - assigned_to= current.variables.requested_for then a + when you should have had a ^. Break your query down by simplifying it till you get correct results then expand it with each new condition. eg: assigned_to=current.variables.requested_for^sys_class_name=alm_hardware^ORsys_class_name=alm_consumable Once this is working you can add your other conditions
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2023 02:39 AM
Hi @Mark Wood ,
Please add ^ before sys_class_name & after ' in your query, it should work.
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2023 02:33 AM - edited 12-21-2023 01:25 AM
Hello @Mark Wood
You can also use the script include and call that script include inside the variable in reference qualifier.
You can refer the below code:
Script Include:
var AssetFilterUtil = Class.create();
AssetFilterUtil.prototype = {
initialize: function() {},
getFilteredAssets: function() {
var requestedFor = current.variables.requested_for;
gs.log("REQ FOR - " + requestedFor);
var assetIds = [];
var arrayUtil = new ArrayUtil();
var assetGr = new GlideRecord('alm_asset');
assetGr.addQuery('assigned_to', requestedFor);
// assetGr.addEncodedQuery('sys_class_name=alm_hardware^ORsys_class_name=alm_consumable^install_statusNOT IN7');
assetGr.addQuery('sys_class_name', 'IN', ['alm_hardware', 'alm_consumable']);
assetGr.addQuery('install_status', 'NOT IN', [7, 8]);
assetGr.addQuery('state', 'NOT', 'retired');
assetGr.query();
while (assetGr.next()) {
gs.log("Inside while");
assetIds.push(assetGr.sys_id.toString());
}
return 'sys_idIN' + arrayUtil.unique(assetIds).join(',');
},
type: 'AssetFilterUtil'
};
Reference Qualifier:
javascript: new AssetFilterUtil(). getFilteredAssets();
Let me know your views on this and Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Regards,
Aniket