Skip to main content
Kinetic Community

Cost Calculations

Import Files
Kinetic Cost js JavaScript
Kinetic Cost Handler Handler
Kinetic Cost Bridge Bridge
Service Item Sample Export
Service Item Sample KURL
   
At times Service Items require the calculation of a total cost based upon the items selected.  Ordering computer accessories is an example of this scenario.  The user can select from several different computer accessories, each of which has an associated cost.

Description

Features

  • Cost data is stored in KS_SRV_Helper form for easier maintenance and reusability.
  • Cost is automatically calculated and set into a Question
  • Reusable and configurable JavaScript.

Contents

  • The JavaScript necessary to implement cost calculation
  • The Bridge Model to retrieve the costs
  • The Task Handler to calculate the cost in the Task Tree (for added process security)
  • The Instructions on the use of Kinetic Cost
  • An example Service Item

Cost Value Configuration

  • Cost Values are defined in the KS_SRV_Helper form.
  • Index Field1 should always be "Kinetic Cost" it defines that this record is for Kinetic Costs
  • Index Field2 defines a category group so that multiple sets of cost records can be created. This may be given any value.  It will be used in the configuration when applied to a Service Item.

Kinetic Cost Index Fields.png

  • When a user selects a value on the Service Item, values are mapped to the data using "Character Field1-4" on KS_SRV_Helper
    • Character Field1 - maps to the Question Label
    • Character Field2 - maps to one potential Question value
    • Character Field3 - defines the cost
    • Character Field4 (Optional)- defines which question on the Service Item defining a quantity of the item
    • Kinetic Cost Value Fields.png
  • In some cases Character Field1 (Question Menu Label) will be the same for multiple records each with a different Character Field2 (Question Value). In the case of Menu Questions and checkbox questions, this addresses the existence of multiple options on a question.
  • Example data has been provided may be imported an seen in this arx file.

Installation

  1. Place the KineticCost.js file in the Bundle on the web server. (ie: kinetic\themes\klean\common\resources\js)
  2. KURL the Bridge Model onto the Server. (Instructions)
    1. After it is KURLed, configure it to the appropriate ARS Bridge on the server in the "Bridge Manager"
  3. Import and configure the Task Handler
  4. Create a "load" event with a "Custom" action on the Page Element of the Service Item which will initialize the functionality
    1. Name the event to any preferred name
    2. User the JavaScript below as an example of code to initialize Kinetic Cost for the Service Item:
      • Parameter 1: costCategory - {Array of Strings} The Cost Category(s) (defined in the field "Index Field2" of the helper records) to use in the search for related cost records
      • Parameter 2: totalQstn - {String} The Questions Label which will be set with the calculated cost value
      • Parameter 3: qstnObjects (Optional)- {jQuery object} jQuery object representing the questions to be evaluated for cost. Default: $('form div .questionLayer') - All Questions on Request
      • Example
    • KINETICCOST.initialize(['Computer Software','Computer Accessories Costs'], 'cost_total',$('form div .questionLayer'));
      
  5. Associate the event to the Bridge Model and Qualification that was imported.Bridge Event.png
  6. Ensure you have proper data in the KS_SRV_Helper form (see below for details

Task Tree

It is important to display a cost to the user before the submit a request.  However it is even more important to calculate the cost again in the Task Tree.  Without this validation, the cost could be maliciously modified before submission.

When the Handler is applied to a Task Tree, it is configured with one parameter.  "Cost Category" represents a set of data defined with this cost category.  This is be the data used when calculating a cost.  "Cost Category" is defined in Index Field2 of the KS_SRV_Helper form.

Calculate Cost Task Handler.png


The Task Node will return the calculated cost of the submitted Service Item.  It is important to validate the cost in the Task Tree for added security.  The value returned by this node is what should be trusted in the process.

How it works

The "Load" event on the page, retrieves all cost information for the Cost Categories defined in the "costCategory" parameter of this event.  This information relates Costs to Question Values and Question Values to Questions.  This data is used in cost calculations.

The initialization described above also binds a change event to all questions defined in the "qstnObjects" parameter of the "Load" event.  When any of these Question Values are changed it initiates the cost calculation. Logic  iterates through these Questions.  At each Question, logic evaluates if the question has an answer and looks to see if a cost has been defined for the Question and the selected Question Value.  If a cost has been defined it adds it to a total and continues to the next Question.  If the Question has a Quantity Question defined for it, the quantity will be retrieved from that question and multiplied by the cost before adding to the total.

At the end of the iteration, the total is placed in the question defined in the "totalQstn " parameter of the "Load" event.

This same basic process and logic is used by the Task Handler when calculating the cost.

Dependencies

  • jQuery