- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2022 01:18 PM
Dear Community,
Through email script how to get the value of field Configuration item (cmdb_ci) of Task table, condition is- it only displays its value when the 'name' of configuration item is of class (sys_class_name)- Computer (Only), rest for any other class it does not show Configuration Item on Tabular format
I tried below email script but not getting result please help, I am new on Coding.
template.print("<tr><td style=\"padding: 5px; border: 1px solid; border-color: grey;\" >");
template.print('Configuration item');
template.print("</td><td style=\"padding: 5px; border: 1px solid; border-color: grey;\" >");
var gr1 = new GlideRecord('cmdb_ci');
gr1.addQuery('name', current.getValue(cmdb_ci));
gr1.addQuery('sys_class_name', "Computer");
gr1.query();
if (gr1.next()) {
template.print(current.getValue(cmdb_ci) == gr1.sys_id);
template.print("</td></tr>");
}
template.print("</table>");
Please provide the revision on code, I shall be grateful.
Thanks!
Solved! Go to Solution.
- Labels:
-
Task Communications Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2022 02:02 PM
Overall Script would look like below.
var gr1 = new GlideRecord('cmdb_ci');
gr1.addQuery('name', current.getDisplayValue('cmdb_ci'));
gr1.addQuery('sys_class_name', "cmdb_ci_computer");
gr1.query();
if (gr1.next()) {
template.print(current.getDisplayValue('cmdb_ci'));
template.print("</td></tr>");
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2022 01:41 PM
and is there any filed that is storing cmdb_ci on the custom form?
if yes which type of field it is ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2022 01:58 PM
I want to print Configuration item field value on this custom table when that field value is of 'Class- Computer', if not then it will not print the Configuration item column on Table (!=).
Answer to your question is 'Yes', Configuration item field itself storing cmdb_ci value on custom table as this custom table extends from inbuilt 'Task' table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2022 02:05 PM
hello you can try this script
var gr1 = new GlideRecord('cmdb_ci');
gr1.addQuery('sys_id', current.cmdb_ci);
gr1.addQuery('sys_class_name', "Computer");
gr1.query();
if (gr1.next()) {
template.print("<table>");
template.print("<tr><td style=\"padding: 5px; border: 1px solid; border-color: grey;\" >");
template.print('Configuration item');
template.print("</td><td style=\"padding: 5px; border: 1px solid; border-color: grey;\" >");
template.print(current.getDisplayValue('cmdb_ci'));
template.print("</td></tr>");
template.print("</table>");
}
Hope this helps
Mark my answer correct if this helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2022 02:23 PM
Thanks Mohith, it not works as expected but it gives a great idea for tweak the script & to perform as required, marking helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2022 01:38 PM
Hi,
Seems like these statements have problem
gr1.addQuery('name', current.getValue(cmdb_ci));
gr1.addQuery('sys_class_name', "Computer");
So, try using below script.
var gr1 = new GlideRecord('cmdb_ci');
gr1.addQuery('name', current.getDisplayValue('cmdb_ci'));
gr1.addQuery('sys_class_name', "cmdb_ci_computer");
gr1.query();
if (gr1.next()) {
template.print(current.getValue(cmdb_ci) == gr1.sys_id);
template.print("</td></tr>");
}