Keystats - Looping Engine

From All n One's bxp software Wixi

Jump to: navigation, search

1 Overview

The bxp looping engine in Keystats allows a creator of a Key Stats report to ensure that the report created is 100% dynamic, i.e. not limiting the report to a set number of time intervals or to a set number of forms. The looping engine should be used in conjunction with the numerous dynamic replacements that bxp key stats module provides or with the user specified custom replacements.

The looping engine greatly enhances the reporting ability of any Keystats report by enabling the creation of 100% dynamic and customisable reports, that could meet many different requirements. When creating a Keystats Report using the looping engine, there are two loop types available: Outer Loop and Internal Loop. The number of Outer Loops are as required, same with Internal Loops. However, every Internal Loop cannot have another Internal Loop inside of it.


When adding loops to a Keystat report, the loops can be added at two levels, Tab level and Graphic level.

In coding terms the looping engine of the bxp Keystats module handles the same as the conventional FOR loop, i.e. Loop the following for X times.


2 Creating an Outer Loop

When creating an Outer Loop, there are three pieces of syntax required:


1) [Loop_Start] -- This alerts the looping engine to the start of an Outer loop section in the report

2) [Loop_End] -- This alerts the looping engine to the end of an Outer loop section in the report

3) [##X##] -- This tells the looping engine that the contents of the current Outer loop should be looped X times


2.1 Outer Loop Structure

       [Loop_Start][##/* LoopCount */##]
        // * Content to Loop and Copy
       [Loop_End]


2.2 Outer Loop In Use Example

Anything in between the Start and End Loop tags will be repeated the set number of times specified. The looped content can be anything: HTML, JavaScript, Keystats, Internal Loops, or even the entire Keystats report.


<!--bxp Key Stats Tab Layout-->
       <table id="objExampleTable">
          <tr>
                <td>Heading 1</td>
                <td>Heading 2</td>
                <td>Heading 3</td>
          </tr>
[Loop_Start][##3##]
          <tr>
                <td>Content  1</td>
                <td>Content 2</td>
                <td>Content 3</td>
          </tr>
[Loop_End]  
         </table>    
   
<!--bxp Key Stats Report Output-->
   <table id="objExampleTable">
          <tr>
                <td>Heading 1</td>
                <td>Heading 2</td>
                <td>Heading 3</td>
          </tr>
          <tr>
                <td>Content 1</td>
                <td>Content 2</td>
                <td>Content 3</td>
          </tr> 
          <tr>
                <td>Content 1</td>
                <td>Content 2</td>
                <td>Content 3</td>
          </tr> 
          <tr>
                <td>Content 1</td>
                <td>Content 2</td>
                <td>Content 3</td>
          </tr> 
         </table>


3 Creating an Internal Loop

When creating an Internal Loop, there are three pieces of syntax required:


1) [Internal_Loop_Start] -- This alerts the looping engine to the start of an Internal loop section in the report

2) [Internal_Loop_End] -- This alerts the looping engine to the end of an Internal loop section in the report

3) [##X##] -- This tells the looping engine that the contents of the current Internal loop should be looped X times

* NOTE: There should never be an Internal Loop inside an Internal Loop. The looping engine of Key Stats will not allow an internal loop to have an internal loop


3.1 Internal Loop Structure

       [Internal_Loop_Start][##/* LoopCount */##]
        // * Content to Loop and Copy
       [Internal_Loop_End]


3.2 Internal Loop In Use Example

Anything in between the Start and End Loop tags will be repeated the set number of times specified. The looped content can be anything: HTML, JavaScript, Keystats, Internal Loops or even the entire Key Stats report.

<!--bxp Key Stats Tab Layout-->
       <table id="objExampleTable">
          <tr>
                <td>Heading 1</td>
                <td>Heading 2</td>
                <td>Heading 3</td>
          </tr>
[Loop_Start][##3##]
    [Internal_Loop_Start][##2##]
          <tr>
                <td>Content  1</td>
                <td>Content 2</td>
                <td>Content 3</td>
          </tr>
    [Internal_Loop_End]
[Loop_End]  
         </table>    
   
<!--bxp Key Stats Report Output-->
   <table id="objExampleTable">
          <tr>
                <td>Heading 1</td>
                <td>Heading 2</td>
                <td>Heading 3</td>
          </tr>
          <tr>
                <td>Content 1</td>
                <td>Content 2</td>
                <td>Content 3</td>
          </tr> 
          <tr>
                <td>Content 1</td>
                <td>Content 2</td>
                <td>Content 3</td>
          </tr> 
          <tr>
                <td>Content 1</td>
                <td>Content 2</td>
                <td>Content 3</td>
          </tr> 
          <tr>
                <td>Content 1</td>
                <td>Content 2</td>
                <td>Content 3</td>
          </tr> 
          <tr>
                <td>Content 1</td>
                <td>Content 2</td>
                <td>Content 3</td>
          </tr> 
          <tr>
                <td>Content 1</td>
                <td>Content 2</td>
                <td>Content 3</td>
          </tr> 
         </table>

4 Key Stat Graphic Looping

When creating a Graphic Keystats, perform the same looping options as above, but instead of adding the looping syntax to the Keystat Tab, the syntax gets added to the actual Keystat that is generating the graphic. The same Keystat syntax is used for both the Outer and Internal Loops.

<!--bxp Key Stats Outer Loop-->
       [Loop_Start][##/* LoopCount */##]
        // * Content to Loop and Copy
       [Loop_End]

<!--bxp Key Stats Internal Loop-->
       [Internal_Loop_Start][##/* LoopCount */##]
        // * Content to Loop and Copy
       [Internal_Loop_End]


5 Dynamic Replacements

The Keystats looping engine allows the use of dynamic replacements. These dynamic replacements include the current count of the loop. The current loop count can be replaced as many times as required. To perform this replacement the following key words should be used:-

1) %91%91LoopCount]] -- This gets replaced with the current loop count for Outer loops 2) %91%91Internal_LoopCount]] -- This gets replaced with the current loop count for Internal loops

5.1 Dynamic Replacements In Use

<!--bxp Key Stats Outer Loop-->
       [Loop_Start][##3##]
            Current Loop Count: [[LoopCount]]
       [Loop_End]

<!--Output-->
       Current Loop Count: 1
       Current Loop Count: 2
       Current Loop Count: 3

<!--bxp Key Stats Internal Loop-->
       [Loop_Start][##3##]
           [Internal_Loop_Start][##2##]
              Current Loop Count: Outer:[[LoopCount]] || Internal: [[Internal_LoopCount]]
           [Internal_Loop_End]
       [Loop_End] 

<!--Output-->
       Current Loop Count: Outer: 1 || Internal: 1
       Current Loop Count: Outer: 1 || Internal: 2
       Current Loop Count: Outer: 2 || Internal: 1
       Current Loop Count: Outer: 2 || Internal: 2
       Current Loop Count: Outer: 3 || Internal: 1
       Current Loop Count: Outer: 3 || Internal: 2


5.2 Dynamic Parameter Replacements

When using the user set dynamic replacements keyStatsCustom, modify the parameters inside an SQL statement. For example, if the statement that counts the number of contacts (CCL's) happens between two dates, by using the Looping engine the report is set up to allow an indefinite amount of dates to be passed in. Instead of creating a different key stat for every iteration of the parameters, use key stats, but replace the parameters that gets passed to it. To use the dynamic replacements for the parameters passed in, use the following syntax (but make sure it is the very last parameter passed to the key stat:


// * Structure
[[intParamAdd:/*Start Position*/;/*Number to Add*/;/*Number to subtract*/]]

// * Examples
[ [intParamAdd:1;2;0]] --> Will replace in the SQl statement as 3
[ [intParamAdd:3;0;2]] --> Will replace in the SQl statement as 1
[ [intParamAdd:[ [LoopCount]];2;0]] --> Will replace in the SQl statement as the current Outer loop count +2
[ [intParamAdd:[ [Internal_LoopCount]];2;0]] --> Will replace in the SQl statement as the current Internal loop count +2


As a Keystat can have multiple parameters to replace, specify where in the statement to perform the replacement. To do this add a specific key word to the places in the SQL statement that need to be replaced. This key word is [ [intParamAdd]]. When the Keystats engine sees this it will replace it with the required value, as outlined above.


// * Replacement Syntax -> [ [intParamAdd:1;2;0]] --> Replace [ [intParamAdd]] with 3

// * SQL Statement before replacement 

SELECT COUNT(intCCL_292_Id) FROM CCL_292 
WHERE dteCCL_292_EndDateTime >= '--parameter[ [intParamAdd]]-- 00:00:00' 
AND 
dteCCL_292_EndDateTime <= '--parameter[ [intParamAdd]]-- 00:00:00';

// * SQL Statement before replacement 

SELECT COUNT(intCCL_292_Id) FROM CCL_292 
WHERE dteCCL_292_EndDateTime >= '--parameter3-- 00:00:00' 
AND 
dteCCL_292_EndDateTime <= '--parameter3-- 00:00:00';


After the replacement has been calculated there is a final option that can be used. This option allows a key stat to further add to the number generated by the above examples. To use this functionality modify the key word [ [intParamAdd]], outlined above, to be [ [intParamAdd:X]]. Replace X with the number you want to add to the dynamic parameter replacement already generated.


// * Replacement Syntax -> [[intParamAdd:1;2;0]] --> Replace [ [intParamAdd]] with 3

// * SQL Statement before replacement 

SELECT COUNT(intCCL_292_Id) FROM CCL_292 
WHERE dteCCL_292_EndDateTime >= '--parameter[ [intParamAdd:0]]-- 00:00:00' 
AND 
dteCCL_292_EndDateTime <= '--parameter[ [intParamAdd:1]]-- 00:00:00';

// * SQL Statement before replacement 

SELECT COUNT(intCCL_292_Id) FROM CCL_292 
WHERE dteCCL_292_EndDateTime >= '--parameter3-- 00:00:00' 
AND 
dteCCL_292_EndDateTime <= '--parameter4-- 00:00:00';