Auto populate reference variable based on another reference variable on a catalog item form. I have reference variable Application referring to 'Name' field on Applications (cmdb_ci_appl) table and another list field called 'Roles' in it. On catalog

jyotsna1
Giga Contributor

Auto populate reference variable based on another reference variable on a catalog item form. I have reference variable Application referring to 'Name' field on Applications (cmdb_ci_appl) table and there is a list field called 'Roles' on same table, which has multiple roles associated to each application (these roles are maintained in a separate custom table). On catalog Item I want to populate roles from this list field values in a variable based on the application selected on catalog form. 

Hope someone helps me get this! Thank you

16 REPLIES 16

Hi,

Can you share what browser error?

Also did you use proper variable name to set the value on form

Regards
Ankur

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

jyotsna1
Giga Contributor

Hi Ankur,

Below is the error

find_real_file.png

Variables Below

find_real_file.png

Catalog Client Script

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

if (newValue == '') {
g_form.clearValue('security_roles');
}

var ga = new GlideAjax('securityroles');
ga.addParam('sysparm_name', "getRole");
ga.addParam('sysparm_appname', g_form.getValue('u_security_roles')); // u_security_roles is field name                                                                                                                     from cmdb_ci_appl table
ga.getXML(callBackMethod);

function callBackMethod(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer != '') {
g_form.setValue('security_roles', answer);
}
}

}

Hi,

the variable should be application and not u_security_roles

correct this line

ga.addParam('sysparm_appname', g_form.getValue('application'));

try adding alert for answer

function callBackMethod(response){
var answer = response.responseXML.documentElement.getAttribute("answer");

alert(answer);
if (answer != '') {
g_form.setValue('security_roles', answer);
}
}

Regards
Ankur

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

jyotsna1
Giga Contributor

Hi Ankur,

 

Sorry! Its the same even after correcting

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

if (newValue == '') {
g_form.clearValue('security_roles');
}

var ga = new GlideAjax('securityroles');
ga.addParam('sysparm_name', "getRole");
ga.addParam('sysparm_appname', g_form.getValue('name')); // Application field name from cmdb_ci_appl table
ga.getXML(callBackMethod);

function callBackMethod(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
if (answer != '') {
g_form.setValue('security_roles', answer);
}
}

}

I got this working with below

Client Script

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

if (newValue == '') {
g_form.clearValue('security');
}

var ga = new GlideAjax('securityroles');
ga.addParam('sysparm_name', "getRole");
ga.addParam('sysparm_appname', newValue);
ga.getXML(callBackMethod);

function callBackMethod(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
// alert(answer);
if (answer != '') {
g_form.setValue('security', answer);
}
}

}

Created a new free text field 'Security' populated values into it and the got them in to list collector field

Reference Qualifier

javascript:'u_security_roleIN'+current.variables.security;