Versions Compared

Key

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

A simplistic example of a logic for Rebate

...

Templates. This logic creates one agreement with one line.

How to use:

  1. Place the code to a new logic under Administration >

...

  1. Logics >

...

  1. Rebate

...

  1. Template Logics.
    IMPORTANT: Review the first 3 lines and change it according to your system:

...

    1. conditionTypeName – Must be the name of an existing

...

    1. Condition Type, otherwise it fails.

    2. customerId – Should be an existing customer Id, but from our experience it may also work with a non-existent Id (advisable for testing purposes only).

...

    1. inputFieldOnConditionType – The name of the input parameter on the line item. It must be the NAME of the input (in case you have the Name different from Label of the input parameter).

  1. Make a new template record under

...

  1. Rebates > Rebate

...

  1. Templates and assign the new logic to it.

  2. Navigate to

...

  1. Rebates > Rebate Agreements and click the

...

  1. Create

...

  1. from Template

...

  1. button.

paste-code-macro
title
languagegroovyTo generate one agreement
def rebateTypeNameconditionTypeName = "RebateOnSale"  //Name of existing RebateCondition Type
def customerId = "CD-00001"  //ID of existing customer
def inputFieldOnRebateTypeinputFieldOnConditionType = "Rebate discount %"  //name of input field on the RebateCondition Type
def lineItemId = "1234567890"  //this should be generated by random generator such as api.uuid(), but ok for first understanding

def agreementLabel = api.stringUserEntry("Agreement Name")

//create a builder for new Agreement, and setup the important header input fields
builder = ratBuilder.fromParams([
        "label"     : agreementLabel,
        "startDate" : api.parseDate("yyyy-MM-dd", "2017-01-01"),
        "endDate"   : api.parseDate("yyyy-MM-dd", "2017-12-31"),
        "payoutDate": api.parseDate("yyyy-MM-dd", "2018-02-01"),
        "targetDate": api.parseDate("yyyy-MM-dd", "2016-12-01"), //calculationDate
])

//set the value of "Customer(s)" input on header level
builder.addOrUpdateInput("ROOT", [
        "label"    : "Customer(s)",
        "name"     : "CustomerGroup",
        "type"     : InputType.CUSTOMERGROUP,
        "value"    : [
                "customerFieldLabel": "Customer Id",
                "customerFieldName" : "customerId",
                "customerFieldValue": customerId
        ],
        "valueHint": customerId
])

//create new line with given existing contractcondition type and setting a value of its input field
builder.addLineItemWithId(lineItemId, rebateTypeNameconditionTypeName)
        .addOrUpdateInput(lineItemId, [
        "name" : inputFieldOnRebateTypeinputFieldOnConditionType,
        "label": inputFieldOnRebateTypeinputFieldOnConditionType,
        "type" : InputType.USERENTRY,
        "value": 10
])

builder.build()