List Collector choices based on Reference field value

ss123
Tera Contributor

Hi!

In the Portal, we have this requirement in the catalog form where we need to filter the List Collector choices (sys_choice table) based on the value selected in Reference field (practice_group table)

 

Example:

When Reference field selected "Group 1", the List Collector choices should be [ G1, G2, G3 ]

 

When Reference field selected "Group 2", the List Collector choices should be [ B1, B2, B3 ]

 

Can I do this filtering via reference qualifier in the Collector field?

 

Thank you for your help.

1 ACCEPTED SOLUTION

@ss123 : As we discussed I have modified the script to cater to the requirement 

 

var ListChoice = Class.create();
ListChoice.prototype = {
    initialize: function() {},
    getChoice: function(input_value) {
        try {
            var private_eui = gs.getProperty('private_equity_aol', '678ea9051b403340fb1fb9dcdd4bcbc6');
            var choices = [];
            var listvalue = new GlideRecord('sys_choice');
            if (input_value == private_eui)
                listvalue.addQuery('dependent_value', input_value);
            else
                listvalue.addEncodedQuery('element=u_transaction_type^name=u_deal_collection^dependent_value=NULL');
            listvalue.query();
            while (listvalue.next()) {
                choices.push(listvalue.sys_id.toString());
            }
            return choices.toString();
        } catch (e) {
            gs.log('Error in Script apple: ' + e);
        }
    },
    type: 'ListChoice'
};

 

 

I hope this solves your issue
Mark this as Helpful / Accept the Solution if this clears your issue

View solution in original post

10 REPLIES 10

@ss123 : 

I feel we can achieve it by calling a script include in the reference qualifier

 

SGoutham_0-1693553414721.png

 

javascript:'sys_idIN'+new ListChoice().getChoice(current.variables.group.toString());

 

SGoutham_1-1693553471412.png

var ListChoice = Class.create();
ListChoice.prototype = {
    initialize: function() {},
    getChoice: function(input_value) {
        try {
			if(gs.nil(input_value))
				return '';
            var choices = [];
            var listvalue = new GlideRecord('sys_choice');
            listvalue.addQuery('dependent_value', input_value);
            listvalue.query();
            while (listvalue.next()) {
                choices.push(listvalue.sys_id.toString());
            }
            return choices.toString();
        } catch (e) {
            gs.info('Error in Script: ' + e);
        }
    },
    type: 'ListChoice'
};

 

 

 

I hope this solves your issue
Mark this as Helpful / Accept the Solution if this clears your issue

ss123
Tera Contributor

@S Goutham 

Tried using the reference qualifier and script include , but still No matches found is showing on the list collector field.

 

I changed the variable value to the exact value  in the ref qualifier. This is what I used:

REFERENCE QUALIFIER: 

javascript:'sys_idIN'+new ListChoice().getChoice(current.variables.u_aol.toString());

SMSS_0-1693554747951.png

 

SCRIPT INCLUDE:

var ListChoice = Class.create();
ListChoice.prototype = {
    initialize: function() {},
    getChoice: function(input_value) {
        try {
			if(gs.nil(input_value))
				return '';
            var choices = [];
            var listvalue = new GlideRecord('sys_choice');
            listvalue.addQuery('dependent_value', input_value);
            listvalue.query();
            while (listvalue.next()) {
                choices.push(listvalue.sys_id.toString());
            }
            return choices.toString();
        } catch (e) {
            gs.info('Error in Script: ' + e);
        }
    },
    type: 'ListChoice'
};

SMSS_1-1693554774581.png

 

@ss123: I verified the script to be returning the proper output can you verify if the sys_id used in the choice table and the one you have selected are the same?

I hope this solves your issue
Mark this as Helpful / Accept the Solution if this clears your issue

ss123
Tera Contributor

@S Goutham 

Yes , I am selecting the correct value in the Reference and the dependent value in the sys_choice is the same:

This is the sys_id of Private Equity: 7f8ee9051b403340fb1fb9dcdd4bcb1e

SMSS_0-1693555767014.png

 

This is dependent value:

SMSS_1-1693555829822.png

 

@ss123 : As we discussed I have modified the script to cater to the requirement 

 

var ListChoice = Class.create();
ListChoice.prototype = {
    initialize: function() {},
    getChoice: function(input_value) {
        try {
            var private_eui = gs.getProperty('private_equity_aol', '678ea9051b403340fb1fb9dcdd4bcbc6');
            var choices = [];
            var listvalue = new GlideRecord('sys_choice');
            if (input_value == private_eui)
                listvalue.addQuery('dependent_value', input_value);
            else
                listvalue.addEncodedQuery('element=u_transaction_type^name=u_deal_collection^dependent_value=NULL');
            listvalue.query();
            while (listvalue.next()) {
                choices.push(listvalue.sys_id.toString());
            }
            return choices.toString();
        } catch (e) {
            gs.log('Error in Script apple: ' + e);
        }
    },
    type: 'ListChoice'
};

 

 

I hope this solves your issue
Mark this as Helpful / Accept the Solution if this clears your issue