- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2017 01:58 AM
Hi All,
I have the below query for a simple list widget filter on the Service Portal to show all incidents that have been raised by the users company. However I need this list to also show any incidents that have been created by a child company if the logged in users company is a parent company, how can I achieve this?
company=javascript:gs.getUser().getCompanyID()^active=true^EQ
Any help is greatly appreciated.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2017 06:32 AM
Hi Sam,
I am able to retrieve the result in background script. Is the script include is in some scoped application ?
gs.print(new CDL_getParentChild().getCompanyCDL(gs.getUserID()))
Give a try with small change in the SI... it should work without parameter as well.
Filter:
companyINjavascript:newCDL_getParentChild().getCompanyCDL()^active=true^EQ^ORDERBYDESCopened_at
Script Include:
var CDL_getParentChild = Class.create();
CDL_getParentChild.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCompanyCDL : function(user) {
if(!user){
user=gs.getUserID();
}
var sysid=[];
var company,com;
var usr = new GlideRecord('sys_user');
usr.addQuery('sys_id',user);
usr.query();
if(usr.next())
{
company = usr.company;
com = usr.email;
}
if( company != '' ) {
if(com.indexOf('@cdl.co.uk')>= 0)
{
var compani = new GlideRecord('core_company');
compani.query();
while(compani.next()) {
sysid.push(compani.sys_id.toString());
}
return sysid;
}
var company1 = new GlideRecord('core_company');
company1.addQuery('parent',company);
company1.query();
while(company1.next()) {
sysid.push(company1.sys_id.toString());
}
sysid.push(company.sys_id.toString());
return sysid.join(',');
} else {
var company2 = new GlideRecord('core_company');
company2.addEncodedQuery('vendor=false^customer=false^NQcustomer=true');
company2.query();
while(company2.next()) {
sysid.push(company2.sys_id.toString());
}
return sysid.join(',');
}
},
type:'CDL_getParentChild'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2017 08:53 AM
Hi Ujjawal,
In order to not stop my script include working for the other question I had, I guess I need a seperate script includes for this question?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2017 05:16 AM
The company.parent is OOTB field. Should work.
Check that for the child companies, the parent attribute is populated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2017 04:52 AM
Don't prefix sys_idIN .... simply return the comma separated sys_ids string from script include.... and also verify the return value using a log statement.
// var result = 'sys_idIN' + incs;
gs.log("testing ... Ids "+incs);
return incs;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2017 05:09 AM
Right Gurpreet this just an idea to implement this. Actually i pasted this script from another thread of mine for same kind of requirement given by Sam in ref qualifier. That is why I left it as is.
Thanks for clarify.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2017 05:30 AM
Hi Gurpreet,
the KPMG_getDetails().getComp script includes was written for us by our implementation partners and is used in other parts of the system to provide the users company and any associated child companies, is there anything else in the filter that is causing that script include to not work? (as it is working elsewhere?)