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

@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

hello @olufsen  i think you marked your answer as the correct one haha.

Can you please mark the appropriate answer as correct ? and close the thread so that it will be removed from un solved list