Go Back   MarcomCentral (PTI) and FusionPro User Communities > Software-Related Talk > The JavaScript Library > Tables & Charts

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old December 13th, 2019, 10:35 AM
PC Nametag PC Nametag is offline
Forum n00b
 
Join Date: Feb 2019
Location: Verona, WI
Posts: 3
Default Javascript N00B trying to figure out error in table creation

Hello, I'm new-ish to programming and Javascript in general (and new to this message board). I have some basic concepts down. I am building a script to create a table and I keep getting the following message when write the script and try to validate it:


uncaught exception:TypeError: this.Cells[argument[i]] has no properties


Here is the code (minus the boring table contents)


new FPTable;
var myTable = new FPTable;
myTable.AddColumns(9293, 9293, 9293);
myTable.AddRows(21);
myTable.Rows[0].Cells[0].SetBorders("None");
myTable.Rows[0].CopyCells(0,1,2,3);

...
return myTable.MakeTags();


Do I need to make a set borders statement for all 21 rows? Surely there is an easier way to write it, but, as I said, I'm fairly new to this.
Any help I would appreciate it.



Reply With Quote
  #2  
Old December 13th, 2019, 11:33 AM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,505
Default Re: Javascript N00B trying to figure out error in table creation

You're creating a table with three columns:
Code:
myTable.AddColumns(9293, 9293, 9293);
Then you're trying to copy the cell from the first column (0) to the second, third, and fourth columns (1, 2, and 3):
Code:
myTable.Rows[0].CopyCells(0,1,2,3);
Obviously there is no fourth column/cell, so you get the error. (Note that, in JavaScript, like in most programming languages, you start counting at zero instead of at one.)

The fix is to copy only to valid columns:
Code:
myTable.Rows[0].CopyCells(0,1,2);
That will copy the first cell (0) to the second and third cells (1 and 2) in the row.

Quote:
Originally Posted by PC Nametag View Post
Do I need to make a set borders statement for all 21 rows? Surely there is an easier way to write it, but, as I said, I'm fairly new to this.
No, you don't need to repeat that statement 21 times. You probably don't need as much repetition as I'm imagining there is in your "boring table contents" either.

A good thing to keep in mind is that, if you find yourself repeating a lot of code, there's almost always a way to reduce it with a "for" loop.

So, you can always do something like this, after adding all the table rows and their data:
Code:
for (var r = 0; r < 21; r++)
{
    for (var c = 0; c < 3; c++)
    {
        myTable.Rows[r].Cells[c].SetBorders("Thin", "Black", "Top", "Bottom", "Left", "Right");
    }
}
There's very similar code in the "Money Table" rule in the Frodo Travel tutorial that gets installed with FusionPro through version 10.

That said, as I mentioned earlier, I'll bet that you can reduce the code that fills in the table rows and their data with a similar for loop. So instead of this:
Code:
myTable.AddRows(21);
I would call myTable.AddRow() in a loop that executes 21 times. It's hard to say exactly what you need to do, since I don't have the rest of the job, or even any idea what your data look like, but it's probably something like this:
Code:
var myTable = new FPTable;
myTable.AddColumns(9293, 9293, 9293);

for (var r = 1; r <= 21; r++)
{
    var row = myTable.AddRow();
    row.SetContents(Field("Name_" + r), Field("Address_" + r), Field("Phone_" + r));
    for (var c = 0; c < 3; c++)
        row.Cells[c].SetBorders("Thin", "Black", "Top", "Bottom", "Left", "Right");
}

return myTable.MakeTags();
Or, equivalently:
Code:
var myTable = new FPTable;
myTable.AddColumns(9293, 9293, 9293);

for (var r = 1; r <= 21; r++)
{
    var row = myTable.AddRow();
    row.Cells[0].SetBorders("Thin", "Black", "Top", "Bottom", "Left", "Right");
    row.CopyCells(0, 1, 2);
    row.SetContents(Field("Name_" + r), Field("Address_" + r), Field("Phone_" + r));
}

return myTable.MakeTags();
Of course, I could make much more specific suggestions if you were to collect up the template and post it here.

You can find a lot of similar examples here on this forum as well, such as:
http://forums.pti.com/showthread.php?t=5235
http://forums.pti.com/showthread.php?t=4411
http://forums.pti.com/showthread.php?t=5160
http://forums.pti.com/showpost.php?p=21703&postcount=2
http://forums.pti.com/showthread.php?t=3179
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});
Reply With Quote
  #3  
Old December 13th, 2019, 12:22 PM
PC Nametag PC Nametag is offline
Forum n00b
 
Join Date: Feb 2019
Location: Verona, WI
Posts: 3
Default Re: Javascript N00B trying to figure out error in table creation

I figured I biffed the code up somewhere. . I also figured there was a for statement I could use. As I said, I'm quite new to this so I'm stumbling around as I learn.


What I will do is as soon as I am done making it and have it to a point where I need 'intervention', I'll post my results and I can see where I can simplify based on feedback. I do appreciate the input.



My end goal is to make agendas on the back side of name tags that consist of variable data. I am trying to learn how to do it so it cuts down on the labor with how we set it up currently. Once you see the template, you'll see what I mean.


I've decided to post the source doc template and the template I was attempting to set up for reference. The xls doc should point to both templates. The source is the original way (customer did want it upside down) and the template 2 pdf is where I was working through it.


I see how the for statement would make it easier. I think I get stuck on how each row of info would have something different in it. Would that be a if...then statement??
Attached Files
File Type: zip agenda.zip (2.80 MB, 3 views)

Last edited by PC Nametag; December 13th, 2019 at 01:00 PM.. Reason: adding additional info
Reply With Quote
  #4  
Old December 13th, 2019, 02:40 PM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,505
Default Re: Javascript N00B trying to figure out error in table creation

Ah, thanks for posting the template and the data. This gives me a much better idea of what you're doing.

And yes, you are definitely on the right track of making things easier for yourself in the long run by using a table instead of trying to manually create and populate 30 different frames. As Obi-Wan once said, you've taken your first step into a larger world.
Quote:
Originally Posted by PC Nametag View Post
I see how the for statement would make it easier. I think I get stuck on how each row of info would have something different in it. Would that be a if...then statement??
Well, sure, this is variable data after all, so obviously each row is different.

The example in my previous post, which was just guessing about what you were trying to do, assumed that you have a series (array) of data fields with consecutive numeric suffixes, such as Name_1, Name_2, Name_3, Address_1, Address_2, Address_3, etc.

As I suspected, your actual data is set up in much the same way, with fields time1, time2, time3, etc., and roomname1, roomname2, roomname3, and so on. And for the most part, that's how the rows of the table go, with time1 and room1 in one row, time2 and room2 in the next row, etc. But, you have some other things mixed in there that don't quite follow that pattern, so the code has to account for that. Therefore, in this case, with the way the data is structured, I'm not sure there's a super-easy "for" loop to reduce all of your logic to.

...

That said, I would consider a data format that's more generic, so that you could have a simpler loop in the rule, and potentially re-use this entire template.

One feature in particular that I think you could really benefit from is the multi-line record feature. This allows you to have basically a row in the Excel file for each row in the table, which makes the table code almost trivial.

I've taken the liberty of transposing the first two records of your data file into a multi-line format, and reworking the table code to read it, along with a bit of extra formatting. See the attached files.

I think this kind of data format is much more flexible, and will enable you to use more generic table code instead of re-writing the code for each new type of event/agenda/tag.

Note that, with this kind of format, you can use the same single data file to contain both the name and other info on the front side of each name tag AND the multi-line data for the agenda on the back. I've added a "name" field (column) to the Excel file; you can add any columns you need for other per-nametag data, with the values on the first line of each multi-line record. (Note also that the name field is also the "trigger" field, specified on the next-to-last step of the Data Source Wizard, so that a new record is denoted when that row in the Excel file has a non-empty value in that name column.)
Attached Files
File Type: zip multi-line.zip (199.8 KB, 6 views)
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});

Last edited by Dan Korn; December 13th, 2019 at 03:03 PM..
Reply With Quote
  #5  
Old December 13th, 2019, 03:24 PM
PC Nametag PC Nametag is offline
Forum n00b
 
Join Date: Feb 2019
Location: Verona, WI
Posts: 3
Default Re: Javascript N00B trying to figure out error in table creation

Wow. My brain just melted like that guy's face does in Raiders of the Lost Ark

Any chance you could point me in the direction of a step-by-step walk through of setting something like that up?
Reply With Quote
  #6  
Old December 13th, 2019, 04:23 PM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,505
Default Re: Javascript N00B trying to figure out error in table creation

Quote:
Originally Posted by PC Nametag View Post
Wow. My brain just melted like that guy's face does in Raiders of the Lost Ark
Hah, no mortal can face my JavaScript code!
Quote:
Originally Posted by PC Nametag View Post
Any chance you could point me in the direction of a step-by-step walk through of setting something like that up?
Yeah, I'm not sure such a walkthrough exists for "something like [this]" in general. The best way to organize the data depends on what you're doing with it.

To some extent, it's a matter of having some experience with how variable data works in general, and understanding what the different ways are that data can be abstracted and structured, and knowing how FusionPro works more specifically. Studying how this example I've put together works is probably a good starting point. Working on more jobs will give you more of a feel for what kinds of repetitive tasks and data structures can be better automated and reduced via abstraction (which is kind of a summation of why computers and programs exist in the first place).

But here's basically what I did: I copied the first row of your data in Excel to a new sheet, and split it up into one row per event. Then I went into the template in Acrobat, and the Data Wizard, and chose the new data file, and checked the "Multi-line records" box, and then set the "Start a new record when field" condition. Then I went into the rule and added the call to FusionPro.GetMultiLineRecords(), and used the returned object to iterate the lines (rows) in the record to output to the table.

Initially, I didn't have the first part of the code in the for loop that puts the Day field value onto a separate line, so the code was simpler. Without any formatting, it's essentially just this:
Code:
var myTable = new FPTable;
myTable.AddColumns(9293, 9293, 9293); 

var XDF = FusionPro.GetMultiLineRecords();
for (var r = 1; r <= XDF.recordCount; r++)
{
    var row = myTable.AddRow();
    row.SetContents(TaggedFromRaw(XDF.GetFieldValue(r, "time")),
                    TaggedFromRaw(XDF.GetFieldValue(r, "event")),
                    TaggedFromRaw(XDF.GetFieldValue(r, "roomname")));
}

return myTable.MakeTags();
You can see this same basic pattern in several examples on this forum by searching for "FusionPro GetMultiLineRecords FPTable" in your favorite search engine, or with this search.

This is what I was talking about in my previous post, that by using multi-line records, you basically have a row in the Excel file for each row in the table, which makes the table code almost trivial.

Then I added the other code to add a row for each new date, as that value changes. The idea is that we remember the day we're on in the dayName variable, outside the loop, then when we find a row where the Day column value is non-empty and different from the one we're remembering (if (day && day != dayName)), we put it into its own row and then remember the new value.

Finally, I added some code for formatting (setting margins, alignment, etc.). That's pretty much the walkthrough!
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 05:22 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
(c) 2011, PTI Marketing Technologies™, Inc.