Pdf Form JavaScript Button- action - javascript

Viewed 18

Upon creating a PDF form, I have a submit button that will send an email. In this email the subject title is populated from the form, and a PDF attachment of the form is attached.

I am trying to write a code for the body section that will display a table (hopefully I can extract the information later). This table generated could use all form data or only a few.

var cToAddr = "email@email.com";

var cSubLine = "Tug Name :" + this.getField("TUG NAME").value +
    " - Date of request : " + this.getField("Date of request").value + " - PORT : " + this.getField("PORT").value + " - Engineering Dept Fuel-Lube Req";

var cBody = "Tug Name|" + this.getField("TUG NAME").value +
    "\n|Date of request | " + this.getField("Date of request").value +
    "\n|PORT | " + this.getField("PORT").value +
"\n|Date of Sounding | " + this.getField("Date of Sounding").value +
    "\n|Product Requested | " + this.getField("Product Requested").value +
"\n|Hurricane Season | " + this.getField("Hurricane Season").value +
"\n|Fuel/Lube - description | " + this.getField("Fuel/Lube - description").value +
"\n|Max compacity | " + this.getField("Max compacity").value +
"\n|Hurricane Levels | " + this.getField("Hurricane Levels").value +
    "\n|Current Level | " + this.getField("Current Level").value + 
"\n|Amount Requested | " + this.getField("Amount Requested").value +
    "\n\n\n|Record soundings of all tanks for each product in space provided below:\n\n\n|Sounding 1.0.0 | " + this.getField("Sounding 1.0.0").value + 
"\n|Sounding 1.0.1 | " + this.getField("Sounding 1.0.1").value +
    "\n|Sounding 1.0.2 | " + this.getField("Sounding 1.0.2").value + 
"\n|Sounding 1.0.3 | " + this.getField("Sounding 1.0.3").value +
    "\n|Sounding 1.1.0 | " + this.getField("Sounding 1.1.0").value + 
"\n|Sounding 1.1.1 | " + this.getField("Sounding 1.1.1").value +
    "\n|Sounding 1.1.2 | " + this.getField("Sounding 1.1.2").value + 
"\n|Sounding 1.1.3 | " + this.getField("Sounding 1.1.3").value +
    "\n|Sounding 1.2.0 | " + this.getField("Sounding 1.2.0").value + 
"\n|Sounding 1.2.1 | " + this.getField("Sounding 1.2.1").value +
    "\n|Sounding 1.2.2 | " + this.getField("Sounding 1.2.2").value + 
"\n|Sounding 1.2.3 | " + this.getField("Sounding 1.2.3").value +
    "\n|Sounding 1.3.0 | " + this.getField("Sounding 1.3.0").value + 
"\n|Sounding 1.3.1 | " + this.getField("Sounding 1.3.1").value +
    "\n|Sounding 1.3.2 | " + this.getField("Sounding 1.3.2").value + 
"\n|Comments | " + this.getField("Comments 1").value +
    + this.getField("Comments 2").value + this.getField("Comments 3").value +
"\n|Engineer | " + this.getField("Engineer").value;

this.mailDoc({

  bUI: true,

  cTo: cToAddr,

  cSubject: cSubLine,

  cMsg: cBody

});

I also tried:

var cToAddr = "email@email.com";

var cSubLine = "Tug Name :" + this.getField("TUG NAME").value +
    " - Date of request : " + this.getField("Date of request").value + " - PORT : " + this.getField("PORT").value + " - Engineering Dept Fuel-Lube Req";

this.mailDoc({

  bUI: true,

  cTo: cToAddr,

  cSubject: cSubLine,

  cMsg: let tableArr = [
  ['Tug', 'this.getField("TUG NAME").value']
  ['Date of Request','this.getField("Date of request").value']
  ['Port', 'this.getField("PORT").value']
  ['Date of Soundings', 'this.getField("Date of Sounding").value']
  ['Product/Service Requested', 'this.getField("Product Requested").value']
  ['Fuel/Lube ( Manufacturer - Specifications)', 'this.getField("Fuel/Lube - description").value']
  ['Amount Requested (Gallons)', 'this.getField("Amount Requested").value']
  ['Maximum Capacity', 'this.getField("Max compacity").value']
  ['Hurricane Level', 'this.getField("Hurricane Levels").value']
  ['Current Level-Gallons', 'this.getField("Current Level").value']
  ['Sounding of Tanks', 'this.getField("Sounding 1.0.0").value + this.getField("Sounding 1.0.1").value +  this.getField("Sounding 1.0.2").value +  this.getField("Sounding 1.0.3").value + this.getField("Sounding 1.1.0").value + this.getField("Sounding 1.1.1").value + this.getField("Sounding 1.1.2").value + this.getField("Sounding 1.1.3").value +  this.getField("Sounding 1.2.0").value + this.getField("Sounding 1.2.1").value + this.getField("Sounding 1.2.2").value + this.getField("Sounding 1.2.3").value+  this.getField("Sounding 1.3.0").value + this.getField("Sounding 1.3.1").value + this.getField("Sounding 1.3.2").value + this.getField("Sounding 1.3.3").value']
  ['Hurricane Season', 'this.getField("Hurricane Season").value ']
  ['Comments', 'this.getField("Comments 1").value + this.getField("Comments 2").value + this.getField("Comments 3").value ']
  ['Submitting Engineer', 'this.getField("Engineer").value']
]
function getCells(tableArr, type) {
  return data.map(cell => `<${type}>${cell}</${type}>`).join('');
}
function createBody(tableArr) {
  return data.map(row => `<tr>${getCells(row, 'td')}</tr>`).join('');
}
function createTable(tableArr) {

  const [headings, ...rows] = tableArr;
  return `
    <table>
      <thead>${getCells(headings, 'th')}</thead>
      <tbody>${createBody(rows)}</tbody>
    </table>
  `;
}
document.body.insertAdjacentHTML('beforeend', createTable(tableArr));

});
0 Answers
Related