- 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 04:07 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2017 03:55 AM
Hi Sam,
Try company=javascript:gs.getUser().getCompanyID()^ORcompany.parent=javascript:gs.getUser().getCompanyID()^active=true^EQ
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2017 04:29 AM
Hi Aleksandar,
The above doesn't work, I'm guessing this is because it is running on the incident table but the parent field is not available on the incident table?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2017 04:42 AM
Hi Sam,
I read this and found this is similar to previous one.
Sharing you another variant of the same script.
var company_user = Class.create();
company_user.prototype = Object.extendsObject(AbstractAjaxProcessor, {
MyFunction: function(){
var cmpny='';
var usr=gs.getUserID();
var us = new GlideRecord('sys_user');
us.addQuery('sys_id',usr);
us.query();
if (us.next())
{
cmpny=us.getValue('company');
}
var com =[];
com.push(cmpny);
var cm= new GlideRecord('core_company');
cm.addQuery('parent',cmpny);
cm.query();
while(cm.next())
{
com.push(cm.getDisplayValue('sys_id'));
}
gs.log('Hi443111'+com);
var userList = '';
var gr = new GlideRecord('sys_user');
gr.addQuery('company','IN',com);
gr.query();
while(gr.next()) {
if (userList.length > 0)
{
userList += (',' + gr.sys_id);
}
else
{
userList = gr.sys_id+'';
}
}
var incs=[];
var inc = new GlideRecord('incident');
inc.addQuery('opened_by','IN',userList);
inc.query();
while(inc.next())
{
if (incs.length > 0)
{
incs += (',' + inc.sys_id);
}
else
{
incs = inc.sys_id+'';
}
}
var result = 'sys_idIN' + incs;
return result;
},
type: 'company_user'
});
Hope this helps.
Regards
Ujjawal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2017 05:17 AM
HI Ujjawal,
Does the above cover both the previous issue of filtering the user list to people of the company and any child companies and this issue of displaying all logs from the company you are part of and any child companies in one script?
Or does the above need adding as a separate script includes?
Apologies just my javascript knowledge is only basic and fairly new to SN