Getting data from dynamic table to email body with Javascript

SSummers

04-04-2019

Good afternoon all.

I am working with a form that consists of 6 user filled text boxes, a dynamic table with 4 columns and a submit button. Currently, I have the submit button take data from one of the text boxes and enter it into the subject line and body of the email.

What I am having difficulty with now is the table. I can get the data from the first row to display in the body of the email, but if new rows are created with data entered, that data does not make it to the email.

This is the code that I have right now.

var subject = "Inventory for: " + mainPage.userDetails.userName.rawValue;

var myDoc = event.target;

var emailBody = "Attached is the inventory for " + mainPage.userDetails.userName.rawValue + ".\n" +

"Model: " + this.hardwareModel  + ".   " +

"Old Service Tag: " + mainPage.eqDetails.eqTable.Row1.oldST.rawValue + ".   " + "New Service Tag: " + mainPage.eqDetails.eqTable.Row1.newST.rawValue + ".   ";

try {

    myDoc.mailDoc({

        bUI: false,

        cTo: "Email addresses",

        cCC: "Email Addresses",

        cSubject: subject,

        cMsg: emailBody,

        cSubmitAs: "PDF"

    });

} catch (e){

}

I realize part of the problem is the code is only looking at the first row. I have some code to count the number of rows, but as to how to get it to step through the number of rows and display each row of data. If it can be set to not display null data that would be nice, but not necessary.

Any help or a point in the right direction would be appreciated.

Thanks in advance,

Sean

Accepted Solutions (0)

Answers (3)

Answers (3)

sergiy2511

10-04-2019

Morning,

first thing I would do is to move your var emailBody = "Attached..." after the tableData loop. Also, if that doesn't help, please let me know if you're getting any error messages in your JS console.

SSummers

10-04-2019

Good Morning.


I have added the script you provided and modified according to field names, but something is still hanging up. I am not sure if it's as simple as I have the 'for...' portion in the wrong spot. I know I'm missing something, and it's probably a simple thing.


Here is the modified script. Thanks,

var tableData = "";

var subject = "Inventory for: " + mainPage.userDetails.userName.rawValue;

var myDoc = event.target;

var emailBody = "Attached is the inventory for " + mainPage.userDetails.userName.rawValue + tableData + ".\n";

for (i=0; i < eqRow.instanceManager.count; i++){

    tableData = tableData + this.resolveNode("eqTable.eqRow[" + i + "].hardwareModel.rawValue + " " + this.resolveNode("eqTable.eqRow[" + i + "].oldST.rawValue + " " + this.resolveNode("eqTable.eqRow[" + i + "].newST.rawValue + "\n";

    };

   

try {

    myDoc.mailDoc({

        bUI: false,

        cTo: "",

        cCC: "",

        cSubject: subject,

        cMsg: emailBody,

        cSubmitAs: "PDF"

    });

} catch (e){

}

sergiy2511

04-04-2019

Hi, you would need to use looping to read the data from your table, something like this:

var tableData = "" //prepare your variable to collect table data

for (i=0; i < Row.instanceManager.count; i++){      //for every row starting from 0 to the last one in your table

tableData = tableData + this.resolveNode("Table.Row[" + i + "].Column1.rawValue + " " + this.resolveNode("Table.Row[" + i + "].Column2.rawValue + " " + this.resolveNode("Table.Row[" + i + "].Column3.rawValue + "\n"; //collect the data from every column and stick it together with " " separator.

}

then include this tableData variable into your emailBody variable.

I should mention that there's probably some (or I should rather say a lot of) mistakes in my syntax above, but at least it will give you an idea to move on. If you'll need further help, you are welcome to share your form with me.

I hope it helps.