populating value using reference qualifier

Amit Dey1
Tera Contributor

I have two catalog variables, comp and comp lead , comp is referencing to a table, if I select a value in comp then comp lead will also needs to be  auto populated, comp is referencing to a table there is a column called lead , we need to populate that lead value in comp lead, how can we achieve this with script include and ref qualifier
by glideajax we can do but our requirement to use ref qualifier.
thanks in advance......

3 REPLIES 3

Sandeep Rajput
Tera Patron
Tera Patron

@Amit Dey1 This can only be done via an onChange client script on comp field. Reference qualifier can be used to filter the values in the reference field, however it doesn't auto populate the value on the reference field.

 

 

Yashsvi
Kilo Sage

Hi @Amit Dey1,

To achieve the auto-population of the comp_lead variable based on the selection in the comp variable using a reference qualifier, you can follow these steps:

Create a Script Include:

  • Create a new Script Include in ServiceNow. This script will contain a function that retrieves the necessary data based on the selected value of comp.

 

var CatalogUtils = Class.create();
CatalogUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getLeadForComp: function(compValue) {
        var leadValue = '';

        // Query the 'comp' table to retrieve the lead value based on compValue
        var compGR = new GlideRecord('comp');
        if (compGR.get(compValue)) {
            leadValue = compGR.lead.toString(); // Assuming 'lead' is a reference field or string field
        }

        return leadValue;
    },

    type: 'CatalogUtils'
});

 

2. Configure the Reference Qualifier:

  • In your comp_lead variable, set up a reference qualifier to filter the records based on the value selected in com

 

 

javascript: new CatalogUtils().getLeadForComp(current.variables.comp.toString());
​

 

This reference qualifier uses the Script Include method getLeadForComp to dynamically filter the comp_lead choices based on the selected comp value.

Thank you, please make helpful if you accept the solution. 

HrishabhKumar
Kilo Sage

Hi @Amit Dey1 ,

If you want to auto-populate comp lead variable based on comp variable, you van use Auto-populate feature in the variable configuration.

Refer this article for detailed steps: https://www.servicenow.com/community/developer-articles/auto-populate-a-variable-based-on-a-referenc...

 

Thanks.

Hope it helps.

If my response turns useful please mark it helpful and accept solution šŸ˜Š.