Need script to reference two tables
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-30-2023 09:28 AM
In catalog, I have 2 variables and both are referring to different tables. In variable var1(referring to pathing_windows) need the patch window based on selected server’s os in var2(referring to table cmdb_ci).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-30-2023 10:55 AM
Hello @Rama Kant ,
Access the variable var1 and modify the reference qualifier using the correct backend field name for 'var2' in the code snippet below:
javascript:"var1="+ current.variables.var2;
Please ensure that the backend name of the field for 'var2' is used accurately.
If you found this helpful, a 'like' is the secret handshake of appreciation!
- Prasad 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-30-2023 06:16 PM
Hi Prasad, Thanks for your response. But its not fulfilling the requirement. The requirement is if user select server abc (eg its a Linux server) in var 2 then var 1 should show all the available patch windows for Linux servers.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-02-2023 09:13 AM
Hi,
Please try with the following reference qualifier script in the 'var1'. It serves the purpose of dynamically querying a GlideRecord in ServiceNow to retrieve a list of sys_ids from the 'cmdb_ci' table based on a specific condition('selected value in var2') and show in the 'Var1'.
javascript: (function() {
newSysIDs = [];
var gr = new GlideRecord('pathing_windows');
gr.addEncodedQuery("OS_field=" + current.variables.var2);
gr.query();
while (gr.next()) {
newSysIDs.push(gr.getValue('sys_id'));
}
return "sys_idIN" + newSysIDs.join();
})();
If this helps you in any way, please mark it as helpful and accept it as a solution. So that others can find the correct solution.
regards,
Prasad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-30-2023 06:18 PM
HI @Rama Kant ,
I trust you are doing great.
Create a Script Include to return the patch windows based on the selected server's OS. This will be used as a dynamic reference qualifier.
var PatchWindowByServerOS = Class.create();
PatchWindowByServerOS.prototype = {
initialize: function() {
},
getPatchWindows: function(os) {
var patchWindows = [];
var gr = new GlideRecord('patching_windows'); // Replace with the actual table name for patch windows
gr.addQuery('os', os); // Assuming 'os' is the field in the 'patching_windows' table that stores the OS type
gr.query();
while (gr.next()) {
patchWindows.push(gr.getValue('sys_id')); // Assuming 'sys_id' is the identifier for the patch windows
}
return 'sys_idIN' + patchWindows.join(',');
},
type: 'PatchWindowByServerOS'
};
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
