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

GlideFather
Tera Patron

Hi @shaik riyaz1,

 

you wrote that script include but that doesn't do anything itself... a script include is just a tool so you need something to make the tool trigger, there are no condition, you must call it, a catalog client script for example.

 

Take this example for inspiration:

GlideAjax Example Cheat Sheet (UPDATED)

_____
No AI was used in the writing of this post. Pure #GlideFather only

I have modified the code, and the value is now being populated:however, its returning the backend value rather than the displ;ay value of the choice field.

 

Client script:

ar businessApp = g_form.getValue('business_application');
if (!businessApp) {
return;
}

var img = new GlideAjax('BusinessApplicationUtils');
img.addParam('sysparm_name', 'getDataCriticality');
img.addParam('sysparm_data_id', businessApp);

img.getXML(function (response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
g_form.setValue('classified_data', answer);

 

script include:

getDataCriticality: function() {

var appID = this.getParameter("sysparm_data_id");

var appData = new GlideRecord("cmdb_ci_business_app);

appData.get(appid):

return appData.u_data_criticality;

},

@shaik riyaz1 is it client script or catalog client script?

CS is for backend view only, while CCS is for portal/employee centre.

 

And also - is it onChange or which one?

 

 

_____
No AI was used in the writing of this post. Pure #GlideFather only

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