Calculated Columns 2010 Copyright Entrinsik, Inc. Enhance your reports with template and script columns PRESENTER: Andrea Dawkins | R&D Project Manager, Entrinsik | 10-11-2010
Apr 01, 2015
Calculated Columns
2010 Copyright Entrinsik, Inc.
Enhance your reports with template and script columns
PRESENTER: Andrea Dawkins | R&D Project Manager, Entrinsik | 10-11-2010
2010 Copyright Entrinsik, Inc.
Two Kinds of Calculated Columns
Template
Script
© 2010 Entrinsik, Inc.
Template Columns
Other columns can be used as placeholders for the real value, like a WordMerge letter
Written with plain text and HTML
Examples:
Joining columns together (like first and last name)
Making a link to another website
In-lining pictures
© 2010 Entrinsik, Inc.
Script Columns
More advanced -- can do anything a Template column can do, plus calculations and conditional output.
Written with JavaScript
Examples:
Color-coding values based on a threshold
Calculating taxes and remaining balance on an order
Counting the number of days since a certain date
© 2010 Entrinsik, Inc.
Template Example # 1: Joining Columns
© 2010 Entrinsik, Inc.
Joining Columns: Drag & Drop
Drag & drop the column headers into the Expression box to get this:
${firstName} ${lastName}
Produces:
Doug Leupen
© 2010 Entrinsik, Inc.
Joining Columns: Mix in HTML
Insert HTML into your column to change the style:
${firstName} <b>${lastName}</b>
Produces:
Doug Leupen
© 2010 Entrinsik, Inc.
Remember… Don’t remove the original columns. Hide them instead.
© 2010 Entrinsik, Inc.
Template Example # 2: Link to a Website
© 2010 Entrinsik, Inc.
Link to a Website: Using the ‘a’ tag
A hyperlink tag in HTML:
<a href = “http://www.entrinsik.com”> Entrinsik</a>
Produces:
Entrinsik
© 2010 Entrinsik, Inc.
Link to a Website: Add in Columns
Use columns in the URL and in the text to display:
<a href = “http://linkedin.com/in/${linkedinID}”>${firstName} ${lastName}’s Profile
</a>
Produces:
Sharon Shelton's Profile
© 2010 Entrinsik, Inc.
Link to a Website: Choose the Window
Open every link in a new window using target = _blank:
<a href = “http://linkedin.com/in/${linkedinID}” target=“_blank">${firstName} ${lastName}’s Profile
</a>
Use target = “MyWindowName” to open links in the same window.
© 2010 Entrinsik, Inc.
Sorting Trick
Add this to the beginning of any
calculated column to choose sorting value:
<a name = “${columnToSortBy}” />
© 2010 Entrinsik, Inc.
Template Example # 3: In-line Pictures
© 2010 Entrinsik, Inc.
In-line Pictures: Use the ‘img’ tag
An image tag in HTML: <img src = “http://entrinsik.com/images/logo.gif” />
Produces:
© 2010 Entrinsik, Inc.
In-line Pictures: Add in Columns
Use columns in the image URL:
<img src = “http://mysite.com/products/${ID}.jpg” />
Specify the height or width:
<img src = “http://mysite.com/products/${ID}.jpg” height=100 />
<img src = “http://mysite.com/products/${ID}.jpg” width=100 />
© 2010 Entrinsik, Inc.
Template Example # 4: Embed a Map
© 2010 Entrinsik, Inc.
Embed a Map: Make the Address
Start by making a template column with an address separated by commas:
${my_street}, ${my_city}, ${my_state} ${my_zip}
© 2010 Entrinsik, Inc.
Embed a Map: Go to Google Maps
Grab the link for “Paste HTML to embed in a website”
Substitute the address in that text with your column variable.
© 2010 Entrinsik, Inc.
Embed a Map: Insert Address
The result should look something like this:
<iframe width="700" height="350" frameborder="0" scrolling="no“ src="http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q= ${destinationAddress}&iwloc=A&output=embed"></iframe>
Make sure to set the column to Hidden and Show in row body.
© 2010 Entrinsik, Inc.
Embed a Map: Result
© 2010 Entrinsik, Inc.
Script Example # 1: Color Coding
© 2010 Entrinsik, Inc.
Color Coding: If Statements
Use an if statement to assign colors based on some condition.
if (condition1) { do this }
else if (condition2) { do that }
else { do the other thing }
© 2010 Entrinsik, Inc.
Color Coding: Setting the Threshold
Actual code using a column called probability:
if ( probability <= 10 ) {
"<div style='color:red'>" + probability + "% </div>";
}
else if ( probability >= 70 ) {
"<div style='color:green'>" + probability + "% </div>";
}
else {
probability + "%";
}
© 2010 Entrinsik, Inc.
Color Coding: Result
JavaScript from the previous slide produces:
© 2010 Entrinsik, Inc.
Avoiding null
Empty values in your script cause “null” to appear, unless you wrap your code with this:
© 2010 Entrinsik, Inc.
if ( probability != null )
{
//code here
}
Script Example # 2: Using Numbers
© 2010 Entrinsik, Inc.
Using Numbers: Calculate Balance Due
Get the balance by subtract the amount paid from the order total (both of which are columns in a report)
orderTotal – amountPaid;
Assign the column as Numeric and right-aligned.
© 2010 Entrinsik, Inc.
Using Numbers: Balance Due? Yes or No
Does the client have a balance due? Figure it out by combining an if statement with your calculation:
if ( orderTotal – amountPaid > 0 ) { “Yes” };else { “No”; }
Now you can group on Yes or No
© 2010 Entrinsik, Inc.
Using Numbers: Paying Taxes
Determine if they paid taxes or not by the state they live in:
if ( state == “NC” || state == “VA” ) {
orderTotal * 0.07;
}
else {
0;
}
© 2010 Entrinsik, Inc.
Script Example # 3: One Multi-value
© 2010 Entrinsik, Inc.
One Multi-value: Inside an Array Multi-values appear to a Script column as an array, or a list of values
inside a single variable.
If you ever see this in your script column, you’re dealing with an array: [Ljava.lang.Object;@1e07cdbte]
Pick an item out of an array by its position in the list surrounded by square brackets: myColumn[3]
© 2010 Entrinsik, Inc.
One Multi-value: Array Indexes Start counting at 0 (the first index):
© 2010 Entrinsik, Inc.
You write in… Which gives you…
orders[0] the 1st multi-value
orders[3] the 4th multi-value
orders[orders.length-1] the last multi-value
orders[orders.length] error, out of range.
Looping
To go through every item in an array, you’ll need to use for loops.
© 2010 Entrinsik, Inc.
for ( var i = 0; i < orders.length; i++ )
{
orderTotal[i] = orderTotal[i]*1.07;
}
Script Example # 4: Counting Days
© 2010 Entrinsik, Inc.
Counting Days: What is Today?
Java has built-in date and time functions that do these calculations for us, and we can access them through the Script column
Today’s date in Java: var today = new Date();
Date in milliseconds (since 1970): myDate.getTime();
© 2010 Entrinsik, Inc.
Counting Days: Subtracting Milliseconds
To count the days past since a date:
var today = new Date();
var diff = today.getTime() - myDate.getTime();
diff / (1000 * 60 * 60 * 24);
The variable diff gives the millisecond difference. Number of days: divide by (1000 * 60 * 60 * 24)
Number of weeks: divide by (1000 * 60 * 60 * 24 * 7)
Number of years: divide by (1000 * 60 * 60 * 24 * 7 * 52)
© 2010 Entrinsik, Inc.
Resources
HTML: http://www.w3schools.com/html/html_examples.asp
JavaScript: http://www.w3schools.com/js/js_examples.asp
CSS (styles): http://www.w3schools.com/css/css_examples.asp
Reports from today: http://trial.entrinsik.com:8080
YouTube examples: http://www.youtube.com/entrinsikinc
More examples: http://delivery.entrinsik.com/portal/index.php?board=6.0
© 2010 Entrinsik, Inc.
Thank you! Any questions?
© 2010 Entrinsik, Inc.