About the estimateCost(order) function
When you create a cost script, the script editor is automatically populated with a basic template script containing the estimateCost(order) function. This function defines the cost estimate information that is displayed on the New Order form.
Use the template as a starting point for your cost script. It contains one line item, which is customizable; you can change the heading text, the description, and how it is calculated. Once you get the hang of it, you can add as many line items as will fit on the New Order form.
In this script, you will:
- Define a line item
- Push a line item into the items array
- Calculate the total cost
- Return the data to the New Order form
Here is an example of a simple cost script with only one line item.
New Order form
Now let's take a look at the template script in a bit more detail.
For each line item you want to display on the New Order form, you need to specify what will be displayed. This includes any individual line items, such as delivery costs, cumulative line items, such as Finishing costs, and any sub totals you might want to display, such as, cost per copy. While the template has only one line item, you can create as many line items as will fit on the New Order form.
New Order form
For each line item, you need to define the following:
The name of the line item as it appears on the New Order form. The name is displayed in bold. Try to limit this to 40 characters or less so that it fits on one line.
Valid format: String.
The description of the line item that is displayed underneath the line item name. You can use any of the following:
The way in which the line item cost is calculated. You can use any of the following:
The css styling option that will be applied to the line item. The following options are available:
Each line item needs to be pushed to an array that is then rendered in the Job Ticketing interface. Make sure you have this push command for every line item. This is done using the following command:
items.push(<line item object name>)
If you have a line item object called printingCostLineItem, the command would be:
You need to declare the items variable at the top of the function.
var items = 
Now that you have defined all of the line item costs, you need to define a calculation for the total estimated cost. This calculation is the sum of specific line item costs. The total is handled differently to the individual line items as it does not need to be pushed to the items array. It is returned directly to the New Order form in Job Ticketing.
In this example, the estimated cost is the sum of the sub-total ($3.80) and the delivery cost ($0.00).
New Order form
You need to declare the total variable at the top of the function.
var total = 0
Now that you have defined each line item and pushed the line items to the items array, you need to send the array and the total cost to the caller of this function. For the estimateCost (order) function, the caller is the New Order form in Job Ticketing.
The value of the total that will be displayed.
(optional) A description of the total estimated cost. This is displayed underneath the Estimated cost. You can use one of the following:
The name of the array ("items") to which the line items have been pushed.