- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2022 01:29 PM
On my record producer, I have 2 variables, Company (default to logged in user's Company) and Service Offering a reference field.
I have a requirement where I need to set value to one particular record on the service offering if logged in user's company is equal to 'Credit Company' and hide the rest, else, display the rest EXCLUDING 'Credit Company'.
I have created a script include and added a reference qualifier on the service offering variable.
However, this doesn't work well. Anyone can review and help?
javascript:new getServiceOfferingByCompany().getServiceOfferingByCompany()
var getServiceOfferingByCompany = Class.create();
getServiceOfferingByCompany.prototype = {
initialize: function() {},
filterCreditOnly: function() {
var answer = ' ';
var company = current.variables.company.getDisplayValue();
//gs.log(company);
//return Offerring = Credit Services if company is Credit Company
if (company == 'Credit Company')
return '127eaa3597741110d682d200f153afd9'; //sys_id of the Offering = Credit Services
var offering = new GlideRecord('service_offering');
offering.addEncodedQuery('state=published^ORstate=^name!=Credit Services^ORname=NULL');
offering.query();
while (offering.next()) {
if (answer.length > 0) {
answer += (',' + offering.sys_id);
} else {
answer = offering.sys_id;
}
}
return 'sys_idIN' + answer;
},
type: 'getServiceOfferingByCompany'
};
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2022 02:06 PM
Thank you everyone. I have combined both of your comments and did some minor tweaks on it and this should be working.
var getServiceOfferingByCompany = Class.create();
getServiceOfferingByCompany.prototype = {
initialize: function() {},
filterCreditOnly: function() {
var answer = [];
var company = current.variables.company;
var serv = '127eaa3597741110d682d200f153afd9';
//return Offerring = Credit Services if company is Credit Company
if (company == 'af1f6e7597741110d682d200f153af0d')
return 'sys_idIN' + serv;
else {
var offering = new GlideRecord('service_offering');
offering.addEncodedQuery('state=published^ORstate=^name!=Credit Services^ORname=NULL');
offering.query();
while (offering.next()) {
answer.push(offering.getValue('sys_id'));
}
return 'sys_idIN' + answer;
}
},
type: 'getServiceOfferingByCompany'
};

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2022 01:36 PM
Update the code as below:
filterCreditOnly: function() {
var answer = [];
var company = current.variables.company.getDisplayValue();
//gs.log(company);
//return Offerring = Credit Services if company is Credit Company
if (company == 'Credit Company')
return 'sys_idIN127eaa3597741110d682d200f153afd9'; //sys_id of the Offering = Credit Services
var offering = new GlideRecord('service_offering');
offering.addEncodedQuery('state=published^ORstate=^name!=Credit Services^ORname=NULL');
offering.query();
while (offering.next()) {
answer.push(offering.getValue('sys_id'));
}
return 'sys_idIN' + answer;
},
Feel free to mark correct, If I answered your query.
Will be helpful for future visitors looking for similar questions 🙂
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2022 01:38 PM
Hello
You have to call the function name like below .in your reference qualifier you called script include name in place of function name which is wrong
Also in script include while comparing company name replace it with sys_id as company is a reference field
javascript:new getServiceOfferingByCompany().filterCreditOnly(current.variables.company)
var getServiceOfferingByCompany = Class.create();
getServiceOfferingByCompany.prototype = {
initialize: function() {},
filterCreditOnly: function(comp) {
if (comp == 'Credit Company sys_id') // replace name with company sys_id
{
return '127eaa3597741110d682d200f153afd9'; //sys_id of the Offering = Credit Services
}
else
{
var offerings=[];
var offering = new GlideRecord('service_offering');
offering.addEncodedQuery('state=published^ORstate=^name!=Credit Services^ORname=NULL');
offering.query();
while (offering.next()) {
offerings.push(offering.sys_id.toString());
}
return 'sys_idIN' + offerings.toString();
}
},
type: 'getServiceOfferingByCompany'
};
Please mark my answer correct if it helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2022 02:09 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2022 02:06 PM
Thank you everyone. I have combined both of your comments and did some minor tweaks on it and this should be working.
var getServiceOfferingByCompany = Class.create();
getServiceOfferingByCompany.prototype = {
initialize: function() {},
filterCreditOnly: function() {
var answer = [];
var company = current.variables.company;
var serv = '127eaa3597741110d682d200f153afd9';
//return Offerring = Credit Services if company is Credit Company
if (company == 'af1f6e7597741110d682d200f153af0d')
return 'sys_idIN' + serv;
else {
var offering = new GlideRecord('service_offering');
offering.addEncodedQuery('state=published^ORstate=^name!=Credit Services^ORname=NULL');
offering.query();
while (offering.next()) {
answer.push(offering.getValue('sys_id'));
}
return 'sys_idIN' + answer;
}
},
type: 'getServiceOfferingByCompany'
};