Variable choice values options are visible separately in another vaible

Manohararuna
Tera Contributor

Hello everyone,

 

          I have two variable, App type (Check box), app name (reference)

App type having the choices Regular , contract 

App name having option coming from reference table those are -Req-emp, Reg-cntrl, Reg-impact, Reg-az600,Contract-emp,Contract-cntrl, Contract-impact, contract-az600

If i select Regular value in App type in app Name only visible --Req-emp, Reg-cntrl, Reg-impact, Reg-az600 these option

If i select Contract value in App type in app Name only visible --Contract-emp,Contract-cntrl, Contract-impact, contract-az600 these option.

Please provide solution to this one

 

Regards,

manohararuna

 

 

7 REPLIES 7

G Ponsekar
Mega Guru

Hi @Manohararuna ,

 

You may need to create script include to return the query back to app name variable

 

call script include in Reference Qualifier of app name variable. Pass contract and regular checkbox variables into function

 

 

javascript: new ScriptInclude().getchoiceQuery(current.variables.u_regular,current.variables.u_contract);

 

And In script include you can perform the operation and return query

 

Sample script include function:

 

    getchoiceQuery: function(regular, contract) {
var type;
if(regular == true){ type = 'Re';}
if(contract == true){type = 'Con';}
 
        var query = 'nameSTARTSWITH'+type;
        return query;

    },

 

If it works for you, mark it as correct and helpful

 

Thanks, GP

Rafael Batistot
Tera Sage

hi @Manohararuna 

 

You may use on Change + Reference Qualifier (advanced) 

 

onChange 

 

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

// Clear previous selection in 'app_name'
g_form.setValue('app_name', '');

// Ensure the field is visible and editable
g_form.setDisplay('app_name', true);
g_form.setReadOnly('app_name', false);

// Refresh the reference field to apply the new filter
g_form.refreshReferenceField('app_name');
}

 

Reference Qualifier

 

var appType = g_form.getValue('app_type');

if (appType == 'Regular') {
// Show only application names starting with 'Req-emp' or 'Reg-'
answer = "nameSTARTSWITHReq-emp^ORnameSTARTSWITHReg-";
} else if (appType == 'Contract') {
// Show only application names starting with 'Contract-'
answer = "nameSTARTSWITHContract-";
} else {
// If no app type is selected, show all records
answer = "";
}

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Manohararuna 

Share catalog item screenshots.

You said you have 2 variables but you are saying 1st is checkbox then checkbox can be either true/false

where are the choices Regular or Contract coming from?

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

Manohararuna_0-1752142774750.png