Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Client script for reference qualifier

charanpatnala
Tera Contributor

Hello Team, I am trying to write a code for variable in a variable set of type reference which should filter the table it is referencing and populate with two possible values using onLoad catalog client script. I tried but haven't found a solution for that can you help me to solve this thanks in advance.

9 REPLIES 9

@Ankur Bawiskar as I mentioned it is in a variable set if I change it will affect all the catalog's in which it was included so, I need to write a script for this

@charanpatnala 

then you can write onChange catalog client script which Applies to your Catalog Item and your variable

Then check if user has selected either of those 2 options

If not then show an field message with error for that variable

something like this

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    //Type appropriate comment here, and begin script below

    g_form.hideFieldMsg('variableName');

    if (newValue == 'sysId1' || newValue == 'sysId2') {
        // do nothing
    } else {
        var message = 'Please select either of these 2 values';
        g_form.clearValue('variableName');
        g_form.showFieldMsg('variableName', message, 'error', true);
    }
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@charanpatnala 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

thank great

phgdet
Mega Sage
Mega Sage

Hi @charanpatnala

The function getDynamicValueFieldRefQual returns a query. In your own function, you can use that variable set to return a default query for other record producers while filtering the referencing table for your specific record producer.

Screenshot 2025-05-22 at 14.12.20.png