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
This content was last updated in 2021. It may still be useful, but could contain outdated information. Please confirm its accuracy before relying on it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-28-2020 05:12 AM
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
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-30-2020 02:44 AM
Hi,
Can you share what browser error?
Also did you use proper variable name to set the value on form
Regards
Ankur
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-30-2020 02:53 AM
Hi Ankur,
Below is the error
Variables Below
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);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-30-2020 03:42 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-30-2020 11:48 AM
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);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-06-2020 12:19 AM
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;