building html setup to be added to work notes thru script include

patricklatella
Mega Sage

Hi community,

working with a script include that is meant to populate the WorkNotes on an incident that is generated from a request.  

What I need to do is to have the script include take the variables from the request and to put them into a grid (see screenshot) and then to have that grid appear as a worknote on the new incident.

So I want something like this:

find_real_file.png

to appear in the worknotes when the new incident is created from the request.

I've done this before in email scripts successfully.   But struggling to get it to work in this context.   Here's my script so far:

//Displays ERP Request Variables in Created Incident Work Notes

var reqObj = new GlideRecord('x_cur_erp_sm_request');

reqObj.get(current.sys_id);

var sInc = new global.reqUtils();

var vArr = sInc.parseVars(reqObj);

template.print("<table style=\" text-align: left;background-color: F2F3F3;border-collapse: collapse;font-family: arial, helvetica, sans-serif;font-size: 12pt; padding: 5px; border: 1px solid; border-color: grey;\">");

//the first row in the table contains the request type

template.print("<tr><td style=\"padding: 5px; border: 1px solid; border-color: grey;\" >");

template.print("Request Type");

template.print("</td><td style=\"padding: 5px; border: 1px solid; border-color: grey;\" >");

template.print(reqObj.template.getDisplayValue());

template.print("</td></tr>");

for (y = 0; y < vArr.length; y++) {

var q = vArr[y].question;

var a = vArr[y].answer;

try {

if (a.toString() != 'undefined'){

template.print("<tr><td style=\"padding: 5px; border: 1px solid; border-color: grey;\" >");

template.print(q);

template.print("</td><td style=\"padding: 5px; border: 1px solid; border-color: grey;\" >");

template.print(a);

template.print("</td></tr>");

}

}

catch (err)

{

}

}

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

incident.work_notes = vArr;//this line populates the work notes on the new incident

thanks!

15 REPLIES 15

vitaly_sukharev
Kilo Guru

Hi Patrick,



If you want to put HTML into Journal field you would need to enclose this HTML into [code][/code] term like this:


[code]


<table>


  <tr>


      <td>a</td>


      <td>b</td>


  </tr>


  <tr>


      <td>c</td>


      <td>d</td>


  </tr>


</table>


[/code]



I modified your code to get this into account:



//Displays ERP Request Variables in Created Incident Work Notes


var reqObj = new GlideRecord('x_cur_erp_sm_request');


reqObj.get(current.sys_id);




var sInc = new global.reqUtils();


var vArr = sInc.parseVars(reqObj);




var note = "[code]";




note += "<table style=\" text-align: left;background-color: F2F3F3;" +


  "border-collapse: collapse;font-family: arial, helvetica, sans-serif;" +


  "font-size: 12pt; padding: 5px; border: 1px solid; border-color: grey;\">";


//the first row in the table contains the request type


note += "<tr><td style=\"padding: 5px; border: 1px solid; border-color: grey;\" >";


note += "Request Type";


note += "</td><td style=\"padding: 5px; border: 1px solid; border-color: grey;\" >";


note += reqObj.template.getDisplayValue();


note += "</td></tr>";




for (y = 0; y < vArr.length; y++) {


  var q = vArr[y].question;


  var a = vArr[y].answer;


  try {


      if (a.toString() != 'undefined') {


          note += "<tr><td style=\"padding: 5px; border: 1px solid; border-color: grey;\" >";


          note += q;


          note += "</td><td style=\"padding: 5px; border: 1px solid; border-color: grey;\" >";


          note += a;


          note += "</td></tr>";


      }


  } catch (err) {}


}


note += "</table>[/code]";




incident.work_notes = note; //this line populates the work notes on the new incident


patricklatella
Mega Sage

Hello Vitaly,


that is some beautiful script, thanks...works perfectly!



Patrick


Hi Vitaly,


couple things though...is there a way to filter out the "undefined" entries?



find_real_file.png


patricklatella
Mega Sage

Hi Vitaly,


it's also duplicating some entries...something I can do to the script to prevent this?  



find_real_file.png