Get Offerings based on user Company, filter with Advanced Reference Qualifier

olufsen
Kilo Sage

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'
};

find_real_file.png

1 ACCEPTED SOLUTION

olufsen
Kilo Sage

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'
};

View solution in original post

6 REPLIES 6

Aman Kumar S
Kilo Patron

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 🙂

Best Regards
Aman Kumar

Mohith Devatte
Tera Sage
Tera Sage

 

Hello @olufsen , Please use the below reference qualifier and script include .Pass the parameter from reference qualifier like below.

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

@olufsen thanks for marking my answer helpul  but please mark this answer correct if it helped you and close the thread so that it will be removed from the unsolved list

olufsen
Kilo Sage

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'
};