How to display/print the value of Configuration Item field of Task table via email script (condition mentioned in description below)?

rishabh31
Mega Sage

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!

1 ACCEPTED SOLUTION

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>");

    }

View solution in original post

16 REPLIES 16

Hi Muhammad- I used the code but not working properly

find_real_file.png

 

 

There is missing quote in below statement

template.print(current.getValue(cmdb_ci) == gr1.sys_id)

So use below statement.

template.print(current.getValue('cmdb_ci') == gr1.sys_id);

In case if you just want configuration item name then use below statement.

template.print(current.getDisplayValue('cmdb_ci'));

Still halfway round, now its showing 'true'

find_real_file.png

like this.

Also I want to print Configuration item field value of custom table when that field value is of 'Class- Computer', if not (!=) then it will not print the Configuration item column on Table.

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>");

    }