Not display the same values in list collector

vijayakumar kon
Tera Contributor

Hello Everyone,

I have two variables with A and B, both are list collectors and getting the data from the same table

In the table I have the data like this -

Name                      shortdescription   Active    Variable

Advertisement        ABC                        true          A

Advertisement         ABC                       true          B
In the variable A reference qualifier - u_active=true^u_variable.name=A^u_shortdescription=ABC; 

same like in B.

In the form I can able to see the values from A and B variables.

Now my requirement is, If I selected the value 'Advertisment' from A then the same value should not be visible in variable B. 

Can anyone please help me on this?

3 REPLIES 3

Chaitanya ILCR
Mega Patron

Hi @vijayakumar kon ,

 

Create a script include

 

ChaitanyaILCR_0-1761728561572.png

var GetValues = Class.create();
GetValues.prototype = {
    initialize: function() {},

    getNames: function(tableName, sysIds) {
        var names = [];
        var gr = new GlideRecord(tableName);
        gr.addQuery('sys_id', 'IN', sysIds);
        gr.query();
        while (gr.next()) {
            names.push(gr.getValue('u_name'));
        }
        return names.toString();
    },

    type: 'GetValues'
};

and update the reference qualifier on the variable B

as below by replacing <put your variable B here> with variable B name

javascript&colon;'u_nameNOT IN'+new GetValues().getNames(current.varialbes.<put you variable B here>)+'u_active=true^u_variable.name=B^u_shortdescription=ABC' 

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

raviteja1600
Tera Guru

Hi @vijayakumar kon ,

 

You need to update the reference qualifier of the Variable B in dynamically when the Variable A is changes. You can use the On Change client script to update the reference qualifier dynamically.

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }

    // Get selected values from Variable A
    var selectedValues = g_form.getValue('variable_A'); // Replace with actual variable name
    var excludedValues = selectedValues.split(',');

    // Build dynamic reference qualifier for Variable B
    var refQual = 'u_active=true^u_variable.name=B^u_shortdescription=ABC';

    // Add exclusion for selected values
    excludedValues.forEach(function(value) {
        refQual += '^sys_id!=' + value;
    });

    // Apply the reference qualifier to Variable B
    g_form.setReferenceQual('variable_B', refQual); // Replace with actual variable name
    g_form.refreshReferenceField('variable_B');
}

 

 If the provided solution is helpful, please mark it as helpful and accept the solution.

 

Regards,

Raviteja

Connectmustaq
Giga Guru

Hi @vijayakumar kon ,

 

To ensure that once a value like 'Advertisement' is selected in variable A, it is excluded from the options in variable B, you can implement dynamic reference qualifiers with scripting that updates based on the selection in A.

Approach:

  • Use client scripting (a onChange script) on variable A.

  • When a value is selected in A, dynamically update the reference qualifier for variable B to exclude that selected value.

Implementation Steps:

  1. Create a client script on the form (variable A's change event):

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
g_form.setReferenceQualifier('variable_b', ''); // reset qualifier
return;
}

// Get the selected value in variable A
var selectedValue = g_form.getValue('variable_a');

// Define a new reference qualifier for variable B to exclude the selected value
var qualifier = 'name!=' + selectedValue; // adjust field if needed

// Set the reference qualifier dynamically for variable B
g_form.setReferenceQualifier('variable_b', qualifier);
}

  1. Configure variables:

    • Variable A: add this script to its onChange client script.

    • Variable B: you may also specify an initial reference qualifier like 'u_active=true^u_variable.name=B^u_shortdescription=ABC', which will be refined dynamically.

  2. Test the form:

    • When you select 'Advertisement' in variable A, variable B's list should exclude 'Advertisement'.

Additional Tips:

  • If your environment uses catalog variables, add this script in the variable's Client Script section.

  • Ensure you use correct field names in the script matching your variable IDs.

 

If it is helpful, please hit the thumbs button please mark the answer as correct based on the impact!!

 

 

Kind Regards,

Shaik Mohammed Mustaq