Need help with Advanced reference qualifier for a service catalog.

Balaram7
Kilo Sage

Hi all,

 

I have requirement to filter the list collector values from the two dependent lookup select boxes.help me with the best approach.

 

There is custom table (u_custom_table) created with three string fields.

1. column A

2. column B

3. column C

These three fields are pulled in to service catalog, two fields as lookup select boxes, second look select box value is dependent on the first look up box variable value,

1. SelectboxA (lookup to ColumnA)

2.SelectboxB (lookup to coumn B)(Dependent on Select boxA)

then we created a third variable as list collector to ensure multiple values need to be selected based on the combination of first look up and second lookup box variables.

3. List Collector C (Dependent on Selectbox A and Selectbox B).


Please help me with advanced reference qualifier with an example to achieve this.

 

1 ACCEPTED SOLUTION

Satishkumar B
Giga Sage
Giga Sage

Hi @Balaram7 

For filtering a List Collector based on the values of two dependent lookup select boxes (SelectboxA and SelectboxB) using an advanced reference qualifier, you can follow this approach:

1. Configure SelectboxA and SelectboxB

Ensure you have two select boxes where:

  • SelectboxA is a lookup to columnA.
  • SelectboxB is a lookup to columnB, which is dependent on the value of SelectboxA.

2. Client Script for SelectboxB

Create a Catalog Client Script to update the options of SelectboxB based on SelectboxA.

Catalog Client Script (Type: onChange)

 

 

 

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

    // Update the options in SelectboxB
    var ga = new GlideAjax('SelectboxBUpdater');
    ga.addParam('sys_id', newValue); // Send value from SelectboxA
    ga.getXMLAnswer(function(response) {
        var options = response.split(',');
        g_form.getControl('selectboxB').innerHTML = options.join('');
    });
}

 

 

3. Script Include for SelectboxB

Create a Script Include to return options for SelectboxB based on SelectboxA.

Script Include

 

 

 

var SelectboxBUpdater = Class.create();
SelectboxBUpdater.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getOptions: function() {
        var columnAId = this.getParameter('sys_id');
        var options = [];
        
        var gr = new GlideRecord('u_custom_table');
        gr.addQuery('columnA', columnAId);
        gr.query();
        while (gr.next()) {
            options.push('<option value="' + gr.columnB + '">' + gr.columnB + '</option>');
        }
        
        return options.join(',');
    },

    type: 'SelectboxBUpdater'
});

 

 

4. Advanced Reference Qualifier for List Collector

To filter List Collector C based on the values of SelectboxA and SelectboxB, use an advanced reference qualifier.

Advanced Reference Qualifier

Reference Qualifier Script

 

 

 

(function refineQuery() {
    var selectboxAValue = g_form.getValue('selectboxA');
    var selectboxBValue = g_form.getValue('selectboxB');

    // Create a GlideRecord query to filter based on the values from SelectboxA and SelectboxB
    var query = 'columnA=' + selectboxAValue + '^columnB=' + selectboxBValue; // Adjust the filter as needed

    return query;
})();

 

 

Check:

  1. Client Script: Updates SelectboxB options based on SelectboxA selection.
  2. Script Include: Provides options for SelectboxB.
  3. Advanced Reference Qualifier: Filters List Collector C based on the selected values of SelectboxA and SelectboxB.

Make sure to adjust field names and table names according to your specific implementation. Test the entire process to ensure that the dependencies and filters are working as expected.

……………………………………………………………………………………………………

Please Mark it helpful 👍and Accept Solution✔️!! If this helps you to understand

View solution in original post

2 REPLIES 2

Satishkumar B
Giga Sage
Giga Sage

Hi @Balaram7 

For filtering a List Collector based on the values of two dependent lookup select boxes (SelectboxA and SelectboxB) using an advanced reference qualifier, you can follow this approach:

1. Configure SelectboxA and SelectboxB

Ensure you have two select boxes where:

  • SelectboxA is a lookup to columnA.
  • SelectboxB is a lookup to columnB, which is dependent on the value of SelectboxA.

2. Client Script for SelectboxB

Create a Catalog Client Script to update the options of SelectboxB based on SelectboxA.

Catalog Client Script (Type: onChange)

 

 

 

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

    // Update the options in SelectboxB
    var ga = new GlideAjax('SelectboxBUpdater');
    ga.addParam('sys_id', newValue); // Send value from SelectboxA
    ga.getXMLAnswer(function(response) {
        var options = response.split(',');
        g_form.getControl('selectboxB').innerHTML = options.join('');
    });
}

 

 

3. Script Include for SelectboxB

Create a Script Include to return options for SelectboxB based on SelectboxA.

Script Include

 

 

 

var SelectboxBUpdater = Class.create();
SelectboxBUpdater.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getOptions: function() {
        var columnAId = this.getParameter('sys_id');
        var options = [];
        
        var gr = new GlideRecord('u_custom_table');
        gr.addQuery('columnA', columnAId);
        gr.query();
        while (gr.next()) {
            options.push('<option value="' + gr.columnB + '">' + gr.columnB + '</option>');
        }
        
        return options.join(',');
    },

    type: 'SelectboxBUpdater'
});

 

 

4. Advanced Reference Qualifier for List Collector

To filter List Collector C based on the values of SelectboxA and SelectboxB, use an advanced reference qualifier.

Advanced Reference Qualifier

Reference Qualifier Script

 

 

 

(function refineQuery() {
    var selectboxAValue = g_form.getValue('selectboxA');
    var selectboxBValue = g_form.getValue('selectboxB');

    // Create a GlideRecord query to filter based on the values from SelectboxA and SelectboxB
    var query = 'columnA=' + selectboxAValue + '^columnB=' + selectboxBValue; // Adjust the filter as needed

    return query;
})();

 

 

Check:

  1. Client Script: Updates SelectboxB options based on SelectboxA selection.
  2. Script Include: Provides options for SelectboxB.
  3. Advanced Reference Qualifier: Filters List Collector C based on the selected values of SelectboxA and SelectboxB.

Make sure to adjust field names and table names according to your specific implementation. Test the entire process to ensure that the dependencies and filters are working as expected.

……………………………………………………………………………………………………

Please Mark it helpful 👍and Accept Solution✔️!! If this helps you to understand

Balaram7
Kilo Sage

Hi @Satishkumar B ,

 

I have one more query, 

Could you please help me with the below.

How to display an error message when an inactive record is selected in a list collector and clear that field value.