Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Table of Contents
minLevel1
maxLevel1

Calculation Logic Architecture Prerequisities

This flow shows how different logics are executed from the Quote perspective:

...

Syntax Check

This dry run is used to discover inputs in the line item. Most of other API calls are mocked. Be aware that the syntax check dry run is executed only once when a new line item is added.

Other Logics Executable from Quote

There are two other types of logics which can be executed from header logics:

  • Configurator Logic

    • The logic is executed after clicking the Open button of Configurator.

      After clicking the Save button of a popup Configurator, a new configurator value is saved to the Quote object. (Quote object is what you get by calling quoteProcessor.getQuoteView().) But you cannot work with the values until the quote is recalculated. Why? All the logic knows is the old quote object since all other calculation logics finished before the configurator logic was executed. You must click the Recalculate button or set automatic recalculation; to learn more see how to recalculate a quote automatically.

  • Template Logic

    • The logic is executed after clicking the download PDF button.

    • From the template logic the whole quote object is accessible through api.getCurrentItem().

Use Cases Summary

Use Case

Pass Values From

To

Solution

1

Quote Header Logic Configurator

Quote Header Logic

Read the configurator value field.

2

Quote Header Logic

Quote Header Logic Configurator

Pass it through the configurator value field, read it using a HIDDEN field inside the configurator.

3

Quote Header Logic

Line Item Logic

Hidden Input (Pre-Phase)

4

Line Item Logic

Header Logic

Read from getQuoteView()
(Post-Phase)

5

Quote Header Logic

Publishing Template Logic

Hidden input or api.currentItem (provides quoteView)

6

Quote Header Configurator

Line Item Logic

Hidden Input

7

Line Item Logic

Quote Header Logic Configurator

Read from getQuoteView()
(Post-Phase), pass it to the configurator trough a value field.

8

Quote Header Logic Configurator

Line Item Logic Configurator

Not possible, please see the details below, including a workaround.

9

Line Item Logic Configurator

Quote Header Configurator

Read from getQuoteView()
(Post-Phase), pass it to the configurator trough a value field.

10

Line Item Logic

Line Item Logic Configurator

Not possible, please see the details below, including a workaround.

Use Case 1: Quote Header Logic Configurator → Quote Header Logic

Step 1: Create the Configurator button in the header logic.

...

{QuoteFeatures=[{Name=firstLineName, firstLineDescr, selected=false}]

Use Case 2: Quote Header Logic → Quote Header Logic Configurator

Step 1: Create a header input field.

...

The QuoteFeatures object is automatically mapped to the input matrix, so the passed values are displayed in an input matrix and you can use PassedValue for whatever purpose you need (e.g. conditional field showing).

Use Case 3: Quote Header Logic → Line Item logic

The solution for this use case is easy: api.global.

...

Instead of using api.retainGlobal = true, you can enable the option “api.retainGlobal defaults to TRUE” in Configuration.

...

Use Case 4: Quote Line Item Logic → Quote Header Logic

This can be useful when e.g. you want to calculate a summary on the header level or display a summary chart in the Custom Quote Header.

...

Code Block
languagegroovy
if(quoteProcessor.isPostPhase()){
  def lineItems = quoteProcessor.getQuoteView().lineItems  
  lineItems.each{ lineItem ->
    
    def sku= lineItem.sku
    def outputItems = lineItem.outputs
    def value = outputItems.find{ it.resultName == "LineItemValue"}?.result
    api.trace("result", "sku: " +sku + " value: "+ value);    
  }  
}

Use Case 5: Quote Header Logic → Publishing (Preprocessing) Logic

If you use publishing templates for quotes, you have to pass data to the preprocessing (publishing) logic. To do that, simply call api.currentItem from the preprocessing logic to get a full quote view.

...

Note: Data will be available in the preprocessing logic only after the quote was saved.

Use Case 6: Quote Header Configurator → Line Item Logic

From the configurator logic you do not have direct access to the quote object. This means you have to pass values from the header logic to the line item logic.

To do this, you need to combine the following use cases:

Use Case 1: Quote Header Logic Configurator → Quote Header Logic.

and then

Use Case 3: Quote Header Logic → Line Item logic

If priceEntityAfterSave is not set to true, the Recalculate button has to be used after saving values in the configurator.

Use Case 7: Line Item Logic → Quote Header Configurator Logic

To read values from a line item logic, use the steps from Use Case 4: Quote Line Item Logic → Quote Header Logic.

Then in the post-phase in the header logic, pass those values through the value property in the configurator. For details see Use Case 2: Quote Header Logic → Quote Header Logic Configurator.

Thanks to the post-phase you can pass these values within one recalculation transaction.

...

Now when you click the Configurator button, you will get values from line items available in that configurator.

Use Case 8: Quote Header Logic Configurator → Line Item Logic Configurator

This may be useful if you want to e.g. set generic parameters in the quote header configurator and then have the configurator pre-filled for each line item and then edit the values for each line item separately.

...

In this case, quote recalculation will not help, as during recalculation there is no syntax check. So let’s talk about a workaround.

Workaround: Create Line Item Configurator in Quote Header

Create a configurator for line items from the header logic and pass it to the line items via the addOrUpdate function.

...

In this case, the line item configurator will always have the same values as the quote header configurator. Any change in the line item configurator will be overwritten on quote recalculation. If you want to keep changes done on the item level, you have to merge it with the header value before you pass them via addOrUpdateInput.

Use Case 9: Quote Line Item Configurator → Quote Header Configurator

The principles are same as in Use Case 7: Line Item Logic → Quote Header Configurator Logic.

The only change is when you iterate over lineItems you need to look inside the configurator value field and collect all needed values.

...

Code Block
    def quote = quoteProcessor.getQuoteView()
    def lineItems = quote?.lineItems
    
    lineItems.each { lineItem ->
        def inputItems = lineItem.inputs
        def value = inputItems.find { it.name == "ConfiguratorName" }?.value
        sum = sum + value?.configuratorFieldValue? : 0
    }

Use Case 10: Line Item Logic → Line Item Logic Configurator

It is possible to add default values to the line item configurator from the line item logic using the following code:

...

The problem here is the function api.getParameter("Configurator A"). It returns the configurator object only if this configurator was not opened before and has no value in the value property. The same happens with e.g. stringuserentry: while it is empty you can get the userEntry object by calling api.getParameter. After you fill it in, no object is returned.

Workaround/Solution

To dynamically fill in configurators in a line item logic, you have to update it using the header logic. Follow the instructions in Use case 4: Quote Line Item Logic → Quote Header Logicand update configurator values while iterating.

Possible Design Issues

“Add new line item” Architecture Awareness

Some of the use cases above are implemented with a header logic updating line items.

...