How to add a table in email notification in workflow?

swathigangadhar
Tera Expert

I want to send an email which has a table in it,

Like Sl.no task                             description

                  1         TASK001             abcd

                  2         TASK002             xyz

How can i achieve this?

1 ACCEPTED SOLUTION

Hello Swathi,



It's my mistake that I didn't give attention that you needed it via workflow.


So, in that case my suggestion would be, creating a new event from the registry and add an Event activity in the workflow and provide the name of the Event there.



find_real_file.png



After that, from the Email->create a Notification and trigger it when the event is fired with the particular event name.


Like,


find_real_file.png



And, in the Notification body, you can include which I posted previously:



find_real_file.png



Also, you can specify the recipients from here itself.



I hope this would solve your requirement more easily rather writing a long piece of mail script and then including it in the mail body.



Please hit Like or mark Helpful or Correct based on the impact.


Thanks,


Rajshekhar Paul


View solution in original post

12 REPLIES 12

Alikutty A
Tera Sage

Hi Swathi,



If the data is dynamic you need to write a notification email script to fetch and print the data in your notification.




http://wiki.servicenow.com/index.php?title=Scripting_for_Email_Notifications#gsc.tab=0




Thank You


Please Hit Like, Helpful or Correct depending on the impact of response


Ankur Bawiskar
Tera Patron
Tera Patron

Hi Swathi,



Below is the sample email script. Invoke this from your email notification using


${mail_script:tableData.emailScript}



email script name - tableData.emailScript;



Script


// current refers to task table here since in example you mentioned task number



template.print('<table style="width:100%">');



  template.print('<tr>');


  template.print('<th>Sr No</th>');


  template.print('<th>Task</th>');


  template.print('<th>Description</th>');


  template.print('</tr>');



  var taskNumbers = 'TASK123,TASK456'; // considering you know these task number information you need to include in email; you can take it from event.parm2


  var count = 1;



  var gr = new GlideRecord("sc_task");


  gr.addQuery("number", "IN" , taskNumbers);


  gr.query();


  while(gr.next()) {


  template.print('<tr>');


  template.print('<td>'+ count +'</td>');


  template.print('<td>'+ gr.number +'</td>');


  template.print('<td>'+ gr.short_description +'</td>');


  template.print('</tr>');


  count++;


  }



  template.print('</table>');



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

I dont want dynamic data, i want to show static data.


Hi Swathi,



Then you can repeat the following code as per your static content:



template.print('<tr>');


  template.print('<th>Sr No</th>');


  template.print('<th>Task</th>');


  template.print('<th>Description</th>');


  template.print('</tr>');



template.print('<tr>');


  template.print('<td>1</td>');


  template.print('<td>TASK001</td>');


  template.print('<td>abcd</td>');


  template.print('</tr>');



template.print('<tr>');


  template.print('<td>2</td>');


  template.print('<td>TASK002</td>');


  template.print('<td>xyz</td>');


  template.print('</tr>');



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader