SlightlyLoony
Tera Contributor

find_real_file.pngYesterday I told you about on-demand functions — and right away I get some emails. Some of you said "Enough with the esoteric, high-falutin' math nonsense — give us something practical!", and the rest said "Surely this doesn't work with reference qualifiers?"

Well, I thought it was pretty clear when I said that on-demand functions work in any script, anywhere, anytime. Apparently not! So here's a practical (if a little unlikely) example: a reference qualifier using an on-demand function. On my instance, I'm going to modify the "Configuration item" field on the incident form so that it only shows computers:

First thing I need is a function that returns an encoded query for every kind of computer. This one will do the trick:


function u_testQual() {
var dbom = new Packages.com.glide.db.DBObjectManager.get();
var tables = dbom.getAllExtensions('cmdb_ci_computer');
var tablesCSV = Packages.com.glide.util.StringUtil.join(tables);
return 'sys_class_nameIN' + tablesCSV;
}

I put that in a Script Include, exactly as I showed you yesterday. Then I went to the incident form, right-clicked on the "Configuration item", selected "Personalize dictionary", and added this to the "Reference qual" field:

javascript:u_testQual();

And that's all there is to it! If you try this, you'll see that the qualifier limits the CIs that show up on that field to all the various kinds of computers...