getReference not working for Onchange client script.

Community Alums
Not applicable

Can anyone help me why getReference not working as expected for Onchange Client script. Below a sample example.

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

var ci= g_form.getReference('cmdb_ci', doAlert);

}
function doAlert(ci) { 
alert("CI is:"+ci.getDisplayValue());
}

1 ACCEPTED SOLUTION

Voona Rohila
Kilo Patron
Kilo Patron

Hi dola

You can use g_form.getDisplayBox('cmdb_ci').value; to get the displayvalue.

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

var ci= g_form.getDisplayBox('cmdb_ci').value;

}




Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

View solution in original post

4 REPLIES 4

bammar
Kilo Sage
Kilo Sage

var ci= g_form.getReference('cmdb_ci', doAlert);

} //This doesnt seem like it has an opening bracket? - is this necessary at all?

Voona Rohila
Kilo Patron
Kilo Patron

Hi dola

You can use g_form.getDisplayBox('cmdb_ci').value; to get the displayvalue.

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

var ci= g_form.getDisplayBox('cmdb_ci').value;

}




Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

Community Alums
Not applicable

Thanks for your response. But can you tell what's issue with getReference.

getDisplayValue() will not work in client script.

 

and if you want to use getReference to get the display value then try below code

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

var ci= g_form.getReference('cmdb_ci', doAlert);

}
function doAlert(ci) { 
alert("CI is:"+ci.name));
}

https://servicenowguru.com/scripting/client-scripts-scripting/gform-getreference-callback/

 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP