Unable to populate Single Line Text variable from inherited Choice field(CMDB_CI)

shaik riyaz1
Tera Contributor

I am working on a Catalog Item and need to auto-populate a Single Line Text variable based on the selected Business Application.

Requirement

  • User selects Business Application (reference to cmdb_ci_business_app)

  • Fetch Data Criticality value from that Business Application

  • Populate it into a Single Line Text variable named classified_data

Field Details

  • classified_data → Catalog variable (Single Line Text)

  • u_data_criticality → Choice field

  • Field is defined on cmdb_ci (base table)

  • Business Application (cmdb_ci_business_app) inherits from cmdb_ci

  • Choices are present only on cmdb_ci

  •  

What i tried:

script include:

 

getDataCriticality: function () {
var sysId = this.getParameter('sysparm_applicationSysId');
var gr = new GlideRecord('cmdb_ci');
if (gr.get(sysId)) {
return gr.getElement('u_data_criticality').getDisplayValue();
}
return '';
}

 

Catalog client script:

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

var app = g_form.getValue('business_application');
if (!app) return;

var ga = new GlideAjax('BusinessApplicationUtils');
ga.addParam('sysparm_name', 'getDataCriticality');
ga.addParam('sysparm_applicationSysId', app);

ga.getXMLAnswer(function (response) {
g_form.setValue('classified_data', response);
});
}

2 ACCEPTED SOLUTIONS

Singh3
Tera Expert

return appData.u_data_criticality returns the backend value. Please replace it with return appData.u_data_criticality.getDisplayValue()
getDisplayValue() returns the display value of the choice field.
Hope this helps!
If this answers your question or provides clarity, please consider marking it as Helpful or Accept as Solution so it can help others in the community as well!

View solution in original post

Hi @shaik riyaz1 
Please use the getDisplayValue() method to  return the display value not the backend value.
like - return appData.u_data_criticality.getDisplayValue() OR return appData.getDisplayValue('u_data_criticality');

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Thank You



 

View solution in original post

5 REPLIES 5

Singh3
Tera Expert

return appData.u_data_criticality returns the backend value. Please replace it with return appData.u_data_criticality.getDisplayValue()
getDisplayValue() returns the display value of the choice field.
Hope this helps!
If this answers your question or provides clarity, please consider marking it as Helpful or Accept as Solution so it can help others in the community as well!