Script include in reporting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2024 05:47 AM
Hi,
I am trying to create a script include that I will call from a report. The script include should list out all company records that have at least one request item associated to it. This is the script for the relationship I created which applies to core_company and queries from sc_req_item. It works:
(function refineQuery(current, parent) {
var ritms = [];
var gr = new GlideRecord('sc_req_item');
gr.query();
while (gr.next()) {
var company = gr.variables.vendor_name;
if (company == parent.getValue('sys_id')) {
ritms.push(gr.getValue('sys_id'));
}
}
current.addQuery('sys_id', ritms);
})(current, parent);
I want to convert this into a script include that will list out all company records that have at least one RITM associated to it. Can someone please help. (I have tried the related list conditions on report but this relationship does not come up to select).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2024 11:31 PM
Try this out -
var CompanyRITMUtils = Class.create();
CompanyRITMUtils.prototype = {
initialize: function() {},
getCompaniesWithRITM: function() {
var companySysIds = [];
var grRITM = new GlideRecord('sc_req_item');
grRITM.query();
while (grRITM.next()) {
var companyId = grRITM.variables.vendor_name;
if (companyId && !companySysIds.includes(companyId)) {
companySysIds.push(companyId);
}
}
var companyRecords = [];
if (companySysIds.length > 0) {
var grCompany = new GlideRecord('core_company');
grCompany.addQuery('sys_id', 'IN', companySysIds);
grCompany.query();
while (grCompany.next()) {
companyRecords.push(grCompany);
}
}
return companyRecords;
},
type: 'CompanyRITMUtils'
};
If you are reporting on core_company table, the you can call this from report in below manner
Sys ID is one of -
javascript:new CompanyRITMUtils().getCompaniesWithRITM()