Jump to content

Add a Rule to a JavaScript table


Susan

Recommended Posts

I've created a table using JavaScript and have an OnJobStart linking to external data. I need to have a rule for the table that says to use Field "Package_Desc" if Field "Event_Desc" is empty. Is that possible? If so, can you tell me where and how to do this. This is my first time building a table so I don't have much experience. I've attached a sample of my job and my table rule is:

 

 

 

if(FusionPro.Composition.isPreview == true || FusionPro.inValidation == true)

{

Rule("OnJobStart");

}

 

 

//Get a count of the total number of records in the external data file

numRecsExtDF = externalDF.recordCount;

 

/*=============================================================================

|| Create arrays to hold values that match the CID of the client's record

||=============================================================================*/

var clientMatch = [];

var eventMatch = [];

var locationMatch = [];

var secMatch = [];

var rowMatch = [];

var seatMatch = [];

var qtyMatch = [];

var priceMatch = [];

var extendedMatch = [];

 

// Step through the external data file and push matches into their respective variables if there is a match

for (var i=1; i <= numRecsExtDF; i++) {

if (externalDF.GetFieldValue(i, 'USERACCOUNTNUMBER') == Field("USERACCOUNTNUMBER")) {

clientMatch.push(externalDF.GetFieldValue(i, 'USERACCOUNTNUMBER'));

eventMatch.push(externalDF.GetFieldValue(i, 'EVENT_DESC'));

locationMatch.push(externalDF.GetFieldValue(i, 'ZONE_DESC'));

secMatch.push(externalDF.GetFieldValue(i, 'SECTION_DESC'));

rowMatch.push(externalDF.GetFieldValue(i, 'ROW_DESC'));

seatMatch.push(externalDF.GetFieldValue(i, 'SEAT_DESC'));

qtyMatch.push(externalDF.GetFieldValue(i, 'TOTAL_COUNT'));

priceMatch.push(externalDF.GetFieldValue(i, 'SEAT_PRICE'));

extendedMatch.push(externalDF.GetFieldValue(i, 'EXTENDED_AMOUNT'));

 

}

}

 

/*=============================================================================

|| Create the table

||=============================================================================*/

new FPTable;

var myTable = new FPTable;

myTable.AddColumns(17500, 9100, 10100, 3170,6300,2480,5150,5600)

myTable.AddRows(clientMatch.length+2); // add 2 additional rows (Header and summary lines)

 

// HEADER ROW FORMATTING

myTable.Rows[0].Cells[0].Font = "Helvetica Neue Bold Condensed";

myTable.Rows[0].Cells[0].PointSize = "10";

myTable.Rows[0].Cells[0].TextColor = "White";

myTable.Rows[0].Cells[0].ShadeColor = "Black";

myTable.Rows[0].Cells[0].ShadePct = 100;

myTable.Rows[0].Cells[0].Margins = new FPTableMargins;

myTable.Rows[0].Cells[0].Margins.Top = 30;

myTable.Rows[0].Cells[0].Margins.Right = 500;

myTable.Rows[0].Cells[0].SetBorders("Very Thin", "Gray", "Top", "Bottom", "Right", "Left");

myTable.Rows[0].CopyCells(0, 1, 2, 3,4,5,6,7); // Apply the same formating to each cell in this row

// HEADER ROW CONTENT

myTable.Rows[0].Cells[0].HAlign = "Left";

myTable.Rows[0].Cells[1].HAlign = "Left";

myTable.Rows[0].Cells[2].HAlign = "Center";

myTable.Rows[0].Cells[3].HAlign = "Center";

myTable.Rows[0].Cells[4].HAlign = "Center";

myTable.Rows[0].Cells[5].HAlign = "Center";

myTable.Rows[0].Cells[6].HAlign = "Center";

myTable.Rows[0].Cells[7].HAlign = "Center";

myTable.Rows[0].SetContents("Event / Package", "Location", "Sec", "Row", "Seat(s)", "Qty", "Price", "Total");

 

// interate through the length of the arrays (data matches from external data file) and create rows

for (var i=1; i<=clientMatch.length; i++) {

// TABLE CONTENT FORMATTING

myTable.Rows.Cells[0].Font = "HelveticaNeueLT Std Cn";

myTable.Rows.Cells[0].PointSize = "9";

 

myTable.Rows.Cells[0].Margins = new FPTableMargins;

myTable.Rows.Cells[0].Margins.Top = 55;

myTable.Rows.Cells[0].Margins.Bottom = 55;

myTable.Rows.Cells[0].Margins.Right = 500;

myTable.Rows.Cells[0].SetBorders("Very Thin", "Gray", "Top", "Bottom", "Right", "Left");

myTable.Rows.CopyCells(0,1,2,3,4,5,6,7); // Apply the same formating to each cell in this row

// CREATE CONTENT FOR EXTERNAL DATA FILE RECORDS

myTable.Rows.Cells[0].HAlign = "Left";

myTable.Rows.Cells[1].HAlign = "Left";

myTable.Rows.Cells[2].HAlign = "Center";

myTable.Rows.Cells[3].HAlign = "Center";

myTable.Rows.Cells[4].HAlign = "Center";

myTable.Rows.Cells[5].HAlign = "Center";

myTable.Rows.Cells[6].HAlign = "Right";

myTable.Rows.Cells[7].HAlign = "Right";

myTable.Rows.SetContents(eventMatch[i-1], locationMatch[i-1], secMatch[i-1], rowMatch[i-1], seatMatch[i-1], qtyMatch[i-1], priceMatch[i-1], extendedMatch[i-1]);

 

}

return myTable.MakeTags();

Link to comment
Share on other sites

I haven't opened up the job to look at, but I think in the first "for" loop, you can just replace this line:

eventMatch.push(externalDF.GetFieldValue(i, 'EVENT_DESC'));

with this:

var eventDesc = externalDF.GetFieldValue(i, 'EVENT_DESC');
if (eventDesc == "")
   eventDesc  = externalDF.GetFieldValue(i, 'PACKAGE_DESC');
eventMatch.push(eventDesc);

Or, equivalently:

eventMatch.push(externalDF.GetFieldValue(i, 'EVENT_DESC') || externalDF.GetFieldValue(i, 'PACKAGE_DESC'));

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...