Contract Item Logic

Contract Item logic is used when you need to:

  • Create input fields for a contract line item.

  • Calculate results (e.g. prices, stats) for a contract line item.

  • Warn users when some lines cannot be calculated.

  • Alert users that there are some business problems with the inputs or results.

  • Generate and Calculate Contract Price Records for the line item.

Logic API

  • Logic Nature: contract

    • Logic Type: Calculation/Pricing

  • Execution Types:

    1. Input Generation – Defines the input fields.

    2. Standard, when the Contract is in draft - calculates the results (e.g. prices) for the line item and provides warnings and alerts.

    3. Standard, when the Scheduled Promotion Calculation task is executed and the Contract is already approved - generates and calculates the Contract Price Records for the contract line item. The logic is not expected to do anything else during this execution besides generation of the Contract Price Records.

  • Information provided to the logic:

    • Input parameters:

      • Names and values of the item’s inputs

      • Names and values of the parent folders and header (i.e. values of inherited input fields)

    • api.currentItem() – ContractLineItem as Map

    • api.global contains:

      • Data stored in api.global in the Contract Header logic pre-phase.

      • Data stored in api.global by execution of the previous contract line (within one recalculation process).

    • binding variables:

      • calculationBase: DMDataSlice - Filter created based on the CustomerGroup, ProductGroup, startDate and endDate

      • priceRecord: IContractPriceRecordManager - This is only available in the normal execution, when the Contract is approved. You can use it to generate the Contract Price Records.

    • context:

      • commandName - info about which operation caused the execution of this logic, e.g. if it was Recalculate, Submit, etc. See api.currentContext() for details.

      • calculationContext - info about what execution is happening right now. In case of the Scheduled Calculations, this will have value "contractRecalculation", so you can use it to detect, if the logic is executed for this purpose. In other cases the value is not provided at all. See api.getCalculationContext() for details.

  • Expected logic execution outcome:

    • From Input Generation mode – input field definitions

    • From Standard mode execution:

      • Results of elements with Display Mode Everywhere – Stored on the contract line item in the field outputs.

      • Warnings – Stored together with the element’s result in which it was raised.

      • Alerts – Stored together with the element’s result in which it was raised.

      • api.global – Data stored here will persist until the next execution of this logic for another contract line item (within one recalculation process).

    • From Scheduled Calculation task:

      • The logic is generating and calculating the Contract Price Records relevant for the current Contract Line Item. The records should be stored to the system via the IContractPriceRecordManager (i.e. "priceRecord" binding).

Code Sample

For example of Contract logic, see Contract_Item_PromotionDiscount.

Example of the Contract Price Record generation.
if (api.getCalculationContext() == 'contractRecalculation') { priceRecords.addOrUpdate( 'newlyGeneratedRecord', ['attribute1': 'value'] ) }

Common Logic Structure

  1. Elements with functions which are used across all logics

  2. Elements with definitions of input fields

  3. Element AbortOnInputGeneration which will abort calculation of the next elements when the logic is executed in the Input Generation mode.

  4. Elements with:

    • Calculations, reading of data from tables

    • Exposing result values, warnings and alerts

    • Generation of Contract Price Records (if used at all)

Found an issue in documentation? Write to us.

Â