- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2024 01:10 PM
Hi, I have an issue with setting up the display value for referenced field. I have a default PDI instance and I modified the Incident table - I added one new referenced field on a form called "u_ci_class" and this field should display the value of "class" for "Configuration Item". The problem is, when I select the list of values from this field I can only select "Configuration Items" values and not the "Class" values as seen in the screenshot. I tried to set display value to true for "class" on referenced table "cmdb_ci" (not able because I do not have enough permission, do not know why) and also on table "cmdb" (was able to set but did not helped). So there is my second question, should be the new field on incident table "u_ci_class" refrenced to table "cmdb_ci" or to table "cmdb" which is the base table? Both these tables has "Class" value available. Thank you for your answer.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2024 05:47 AM
yes, my bad, didn't realized it that class field is not reference type. So we have to add some more code lines to get the Table name of that class from table "Tables [sys_db_object]"
Here is the code, you can test, it's working for me.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var cmdbci = g_form.getReference("cmdb_ci", setClass);
function setClass(cmdbci) {
var classTableName = new GlideRecord('sys_db_object');
// Use get method
classTableName.get('name', cmdbci.sys_class_name );
//alert("Class Name->"+classTableName.label);
g_form.setValue("u_ci_class", classTableName.label);
}
}
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2024 01:29 PM
Hi @Martin_samek ,
Seems like you are trying to set class field with the "Class of Selected Configuration Item". In that case, what's purpose of making this class field "reference type".
You just need to set this class field value with configuration item's class value using the dot walking.
-Thanks,
AshishKM
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2024 01:34 PM
Hi Ashish, that's exactly what I am trying to achieve but without success... Does it mean that I should set the type of this field for example on "string" instead of "reference" and then I should use onChange client script to getReference() and setReference to set class of selected configuration item? Or what is your proposed solution? Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2024 02:38 PM - edited ‎02-19-2024 02:42 PM
yes, I am referring the same. try it, in case any issue with [onChange] client script then share the code.
var cmdbci= g_form.getReference("cmdb_ci", setClass);
function setClass(cmdbci){
g_form.setValue("u_ci_class",cmdbci.class); // check for displayvalue
}
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2024 02:52 PM
Your option is working with small modification, I had to change last line from:
g_form.setValue("u_ci_class",cmdbci.class); // check for displayvalue
to: g_form.serValue("u_ci_class", cmdbci.sys_class_name);
Otherwise, the value returned was undefined, now the returned value is "cmdb_ci_computer" which is correct but there is still prefix "cmdb_ci_" which is not intended to be part of returned value.