Informer JavaScript Guide - Enrole.com - Canisius Center for [PDF]

No information is available for this page.Learn why

0 downloads 3 Views 1MB Size

Recommend Stories


[PDF] JavaScript for Kids
When you talk, you are only repeating what you already know. But if you listen, you may learn something

[PDF] JavaScript for Kids
Come let us be friends for once. Let us make life easy on us. Let us be loved ones and lovers. The earth

[PDF] JavaScript for Kids
Pretending to not be afraid is as good as actually not being afraid. David Letterman

JavaScript The Definitive Guide 6th Edition Pdf
The happiest people don't have the best of everything, they just make the best of everything. Anony

sees informer
Raise your words, not voice. It is rain that grows flowers, not thunder. Rumi

JavaScript Tools Guide
No matter how you feel: Get Up, Dress Up, Show Up, and Never Give Up! Anonymous

JavaScript For Kids For Dummies Pdf
Ego says, "Once everything falls into place, I'll feel peace." Spirit says "Find your peace, and then

JavaScript For Kids For Dummies Pdf
Why complain about yesterday, when you can make a better tomorrow by making the most of today? Anon

([PDF]) JavaScript For Kids For Dummies
Make yourself a priority once in a while. It's not selfish. It's necessary. Anonymous

JavaScript: The Definitive Guide
Love only grows by sharing. You can only have more for yourself by giving it away to others. Brian

Idea Transcript


Informer JavaScript Guide

©2012 Entrinsik, Inc.

Table of Contents Table of Contents ......................................................................................................................................... 2 Chapter 1: Introduction ............................................................................................................................... 6 About Calculated Columns........................................................................................................................ 7 Template vs. Script ................................................................................................................................ 7 What Is JavaScript? ............................................................................................................................... 7 Java vs. JavaScript – Are They The Same Thing? ................................................................................... 8 Informer JavaScript ............................................................................................................................... 8 Chapter 2: Objects: A Brief Introduction ..................................................................................................... 9 In This Chapter ........................................................................................................................................ 10 Introduction to Objects ....................................................................................................................... 10 Interacting With Objects ..................................................................................................................... 10 Informer Objects ................................................................................................................................. 11 Chapter 3: Informer JavaScript .................................................................................................................. 12 In This Chapter ........................................................................................................................................ 13 Operators ................................................................................................................................................ 13 JavaScript Syntax ..................................................................................................................................... 13 Variables ................................................................................................................................................. 14 Variable Values ................................................................................................................................... 14 Variable Names ................................................................................................................................... 14 Context Variables ................................................................................................................................ 14 Creating Script Columns .......................................................................................................................... 15 Statements .......................................................................................................................................... 16 Simple Columns................................................................................................................................... 16 Literal Values ................................................................................................................................... 16 Column or Variable Value ............................................................................................................... 17 Calculation Result............................................................................................................................ 17 Column Type ................................................................................................................................... 18 Exercise ............................................................................................................................................... 18 Complex Columns ............................................................................................................................... 19 Exercise ............................................................................................................................................... 19

Page 2

Conditional Statements ...................................................................................................................... 19 If Statements ................................................................................................................................... 19 Conditions ....................................................................................................................................... 21 Switch Statements .......................................................................................................................... 22 Exercise ............................................................................................................................................... 23 Controlled Loops ................................................................................................................................. 23 For Loops ......................................................................................................................................... 23 While Loops..................................................................................................................................... 24 Do/While Loops .............................................................................................................................. 25 Loop Controls .................................................................................................................................. 25 Exercise ........................................................................................................................................... 26 Chapter 4: Data Types ................................................................................................................................ 27 In This Chapter ........................................................................................................................................ 28 Informer Data Types ............................................................................................................................... 28 Numeric Data Type ................................................................................................................................. 28 String Data Type ...................................................................................................................................... 28 String Properties, Methods & Operations .......................................................................................... 29 Length ............................................................................................................................................. 29 Concatenation ................................................................................................................................. 29 Substrings ........................................................................................................................................ 29 Finding a String in a String .............................................................................................................. 30 Breaking Apart a String ................................................................................................................... 30 Changing Case ................................................................................................................................. 30 Exercises .............................................................................................................................................. 31 Date Data Type........................................................................................................................................ 31 Date Methods and Operations ........................................................................................................... 31 Creating a Date Variable ................................................................................................................. 31 Changing the Date Format .............................................................................................................. 32 Getting the Components of a Date ................................................................................................. 33 Setting the Date .............................................................................................................................. 34 Comparing Dates............................................................................................................................. 34 Date Math ....................................................................................................................................... 36

Page 3

Exercises .............................................................................................................................................. 38 Array Data Type ...................................................................................................................................... 39 Creating Array Variables ..................................................................................................................... 39 Java Version 6 Arrays ...................................................................................................................... 39 Java Version 7 Arrays ...................................................................................................................... 39 Referencing Values in the Array.......................................................................................................... 39 Determining the Size of the Array....................................................................................................... 40 Stepping Through an Array ................................................................................................................. 40 Summing Up the Values in an Array ............................................................................................... 40 Creating a New Array ...................................................................................................................... 40 Sorting Arrays .................................................................................................................................. 41 Finding the Minimum and Maximum Value ................................................................................... 42 Converting Arrays to Strings ........................................................................................................... 42 Multi-dimensional Arrays................................................................................................................ 42 Exercises .............................................................................................................................................. 42 Functions ................................................................................................................................................. 43 Exercises .............................................................................................................................................. 45 Appendix A: JavaScript Exercise Solutions ................................................................................................. 46 JavaScript Exercise Solutions .................................................................................................................. 47 Chapter 3............................................................................................................................................. 47 1. Calculated Column to display "Hello World" .............................................................................. 47 2. Calculated Column to display value of Company Name ............................................................. 47 3. Calculated Column of order total for each line........................................................................... 47 Switch Statements .............................................................................................................................. 47 1. "Backordered" if Quantity exceeds Units in Stock ...................................................................... 47 Loops ................................................................................................................................................... 47 1. Sum of numbers 1 to 50 ............................................................................................................. 47 2. Sum of numbers 1 to 50, but stops when the sum reaches 50 ................................................. 48 Do While Statement ........................................................................................................................ 48 While Statement ............................................................................................................................. 48 3. Calculated Column of the Odd numbers .................................................................................... 48 Chapter 4............................................................................................................................................. 49

Page 4

1. Number of Characters in the Last Name field............................................................................. 49 2. Concatenate first and last name together in lastname, firstname format ................................ 49 3. Calculated column that displays the first initial, a period, a space, and first 3 of the last name ........................................................................................................................................................ 49 4. Customer name to all upper case .............................................................................................. 49 Challenge - Last name field in upper case for odd numbered positions ........................................ 49 Dates ................................................................................................................................................... 50 1. Pull Month, Day and 4-Digit Year out of date ............................................................................ 50 2. Use the Simple Date Format to format date as 12062012 (month,day, year without delimiter) ........................................................................................................................................................ 50 3. Calculated column that displays "Late Shipment" or "On Time" ............................................... 50 4. Calculated column to display number of days between order date and ship date (fulfillment date) ................................................................................................................................................ 50 Arrays .................................................................................................................................................. 51 1. Number of in an order (or number of items in an array) ........................................................... 51 2. Calculated column that displays a message if one of the quantities is above 70 ...................... 51 3. Calculated Column that creates an array of the extended price of each line item ................... 51 4. Calculated column that adds the line extended price to give an order total ............................. 51

Page 5

Chapter 1: Introduction

Page 6

About Calculated Columns Informer allows you to extend your reporting capabilities by adding calculated columns. Calculated columns use report data, literal values, or other data to do calculations, such as adding two column values together or concatenating first name and last name together. But that is not all they do. They are very powerful and can make your life much easier when generating reports. This class will help you understand how to write script calculated columns using JavaScript.

Template vs. Script There are two different kinds of calculated columns in Informer: template and script. Template columns use plain text and HTML to format data. Placeholders, similar to those used in mail merge, allow you to insert column values into the results of the calculation. Template columns only work with single-value columns, and they cannot do computations or conditional statements. Script columns utilize the JavaScript language to write more complex calculated columns. You can do everything in a script column that you can with a template, as well as those things you can’t. These are the columns on which this class will focus.

What Is JavaScript? JavaScript was developed in 1995 by Netscape for use in their web-browser. The browser did not survive the browser wars, but fortunately, JavaScript is still around. It is primarily used as a client-side scripting language, meaning it is executed on the desktop and not the server. It gained popularity in the programming world when the Ajax development platform was introduced in 2005. It is supported in all major browsers.

Page 7

Java vs. JavaScript – Are They The Same Thing? The simple answer here is “No”. They are two totally different languages, although the JavaScript syntax was influenced by Java. But that is where the similarities stop.

Java

JavaScript

Compiled to bytecode

Interpreted at runtime

Strongly Typed

Weakly Typed

Class Based Hierarchy

Prototype-based Hierarchy

Informer JavaScript Informer JavaScript is hybridization of JavaScript. Normally, when you request a webpage, the server sends the page to the browser where JavaScript is interpreted and executed.

Browser JavaScript

document.write(“Hello World”); alert(“DANGER Will Robinson!”); window.print();

With Informer, however, JavaScript is interpreted within the Informer Java application on the server, and the results are then sent to the browser for rendering.

Informer Application

Results

Browser

JavaScript

Because of this, you cannot affect any of the browser objects in the Document Object Model (DOM), but, this also means you have access to standard Java objects:

var today = new java.util.GregorianCalendar();

Page 8

Chapter 2: Objects: A Brief Introduction

Page 9

In This Chapter In this chapter, we will:  Define objects  Learn how to interact with objects  List the different objects in Informer

Introduction to Objects An object can be thought of as any thing. Specific objects belong to the general classes of objects. For example, a pen belongs to a class “pens”. Classes of objects have certain common characteristics, or properties.

Pens Ink color Point type Style Tip size

A specific pen is an instance of the class Pen. This is called instantiation. Data can be put in classes as well. Dates, for example, are an example of a class of data. All dates have characteristics as well.

Dates Month Day Year

Interacting With Objects In order to use objects, you need to interact with them. Using our pen example, I may want to know what color of ink is in my pen. Or, I may want to extract the month from my date object, or set the day of the month. Methods and functions are used to interact with objects. So, what’s the difference between a method and a function? Technically speaking, a method takes no arguments, where a function does. For example, if I want to get the pen color, I do not need to pass anything to determine that value. The color is what it is. That would be a method. If, on the other hand, I want to add a certain number of days to my date, I would need to pass the number of days to add. That would be a function. Basically the two are synonymous. Both perform actions on an object. For the purposes of this class, we will use the term method for both methods and functions. Page 10

To use (or call) a method, you simply state the object name, followed by a period, and then the name of the method.

myDate.getMonth() The empty parentheses are necessary if the method takes no arguments. Objects also have properties as we mentioned earlier. These are values associated with the particular object. For example, a string object has a length property that tells how many characters are in the object. Properties are referenced in essentially the same way as methods, except they do not take any arguments.

firstName.length Informer Objects In Informer, columns are objects. The specific type object class depends on the data type of the column.

Informer Data Type

Object Type

Class Name

Text Date (From U2) Date (From SQL) Boolean Numeric Multi-value

JavaScript Java Java JavaScript JavaScript JavaScript

String Object java.util.Date java.sql.Timestamp or java.sql.Date Boolean Object Number Object Array Object

We will go into each of these objects in Chapter 4. If you want to find what methods or properties are available for a specific type of object, refer to either the w3schools.com website for JavaScript objects, or the Java documentation found at the Oracle.com website. Think of something you own as an object (a car, pet, etc.). What would its class be? What kind of properties would it have?

Page 11

Chapter 3: Informer JavaScript

Page 12

In This Chapter In this chapter, we will:  Show the operators used in JavaScript statements  Discuss the rules for JavaScript statements  Introduce variables  Write a simple script column  Discuss conditional statements  Discuss controlled loops

Operators The following list shows the operators that are used when writing your script columns. JavaScript Operators + * / % = == != > < >= 18 Variable or Column Name

Comparison Operator

Comparison Value

firstName == “John” qtyOnHand 2): “Is more than 2”; break; default: “Must be equal to 2”; } Exercise 1. Using the Order Details Report, create a calculated column that displays a message “Backordered” if the Quantity exceeds the Units in Stock, or no message if not.

Controlled Loops Controlled loops allow you to execute code repeatedly with a different value each time. There are 3 types of controlled loops: for, while, and do.

For Loops For-loops execute a block of code a given number of times. It has the following syntax:

for (statement 1; statement 2; statement 3) { Code block to execute } Statement 1 – the statement executed the first time into the loop. Typically this declares the variable that is used as the loop counter and sets the initial value. Statement 2 – this is the condition statement which controls how long the loop is to run.

Page 23

Statement 3 – the statement that is executed at the end of each loop. Typically this increments or decrements the loop counter defined in statement 1. In this example, we will create a loop that adds together the numbers 1 through 5.

var x = 0; for (var i = 1; i

Smile Life

When life gives you a hundred reasons to cry, show life that you have a thousand reasons to smile

Get in touch

© Copyright 2015 - 2024 PDFFOX.COM - All rights reserved.