- 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-24-2024 05:39 AM
Hi @nitish99,
Thanks for your observation, as you can see, we used the call by reference method and inside that GlideRecord's get() method,
The purpose of get method to retrieve exact record without using other resources like below, so its quick and fast.
- addQuery
- query
- next
Feel free to add more on this, good to learn.
-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 02:39 PM
Hi @Martin_samek
Reference fields display only one field value which is set Display as true.
Since you created a Ref field, to the cmdb_ci table which is already there, it will show the same display value as the one for Configuration Item.
You have to create a String type field and use onChange CS of Configuration Item field to set the class in your custom field.
Regards,
Nitish