Interface RATBuilder
In a Rebate Agreement Template logic, an instance is available as the ratBuilder binding variable. You never
create it yourself. Call fromParams(Map) or fromExisting(String) to get a RATBuilder.RABuilder, chain
the changes you want on that Rebate Agreement, and finish the chain with build(). One logic run can create
several Rebate Agreements this way, one RATBuilder.RABuilder for each.
Note: The builder methods do not change any data when you call them. They record the requested operations, and the application runs the recorded operations after the logic finishes without errors. If the logic fails, no Rebate Agreement is created or changed. In the syntax check mode, the recorded operations are not run at all.
The application runs the recorded operations in batches of up to 100 Rebate Agreements, each batch in its own
transaction. The chains started with fromExisting(String) run first, then the chains started with
fromParams(Map). If an operation fails, for example because of an unknown field name or Rebate Type, the
whole batch is rolled back: no Rebate Agreement of that batch is created, including the ones whose operations were
valid. The other batches are not affected. The logic does not get the error and the template run does not fail. The
result message of the run gives the number of Rebate Agreements that were not created, and the server log has the
details.
Example:
def lineItemId = api.uuid()
def builder = ratBuilder.fromParams([
"label" : api.stringUserEntry("Agreement Name"),
"startDate": api.parseDate("yyyy-MM-dd", "2027-01-01"),
"endDate" : api.parseDate("yyyy-MM-dd", "2027-12-31"),
])
builder.addLineItemWithId(lineItemId, "RebateOnSale")
.addOrUpdateInput(lineItemId, [
"name" : "Rebate discount %",
"label": "Rebate discount %",
"type" : InputType.USERENTRY,
"value": 0.14
])
builder.build()
- Since:
- 3.0 - Sea Breeze
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceBuilder for a Rebate Agreement created from a Rebate Agreement Template (RAT). -
Method Summary
Modifier and TypeMethodDescriptionfromExisting(String RAuniqueName) Starts building a Rebate Agreement from an existing one.fromParams(Map params) Starts building a Rebate Agreement from parameters.List<RATPlaceholder> Returns the placeholders registered so far withregisterPlaceholder(InputType, String), in the order of registration.registerPlaceholder(InputType type, String name) Registers a placeholder that can later be applied withRATBuilder.RABuilder.applyPlaceholder(String, Object).Returns the unique name of the target Rebate Agreement, as sent in the request that runs the template.Returns the typed ID of the Rebate Agreement Template whose logic is running.
-
Method Details
-
templateTypeId
String templateTypeId()Returns the typed ID of the Rebate Agreement Template whose logic is running. Use it when the logic needs to know which template it was started from, for example to write the template reference into a field of the new Rebate Agreement.This method only reads a value and does not record any operation. When the logic runs outside a template execution (for example, in the syntax check of the logic), it returns
null.Example:
def templateId = ratBuilder.templateTypeId()- Returns:
- the template type id, or
nullwhen the logic does not run for a specific template - See Also:
-
targetRAUniqueName
String targetRAUniqueName()Returns the unique name of the target Rebate Agreement, as sent in the request that runs the template. Use it when the template is run for one specific agreement, for example to pass it tofromExisting(String).This method only reads a value and does not record any operation. It returns
nullwhen the request does not name a target Rebate Agreement, and always in a test run or syntax check of the logic.Example:
def target = ratBuilder.targetRAUniqueName() if (target != null) { ratBuilder.fromExisting(target).build() }- Returns:
- the unique name of the target Rebate Agreement, or
nullwhen no target is set - See Also:
-
fromExisting
Starts building a Rebate Agreement from an existing one.When the recorded operations run, the application creates a copy of the existing Rebate Agreement, including its line items, and applies the chained changes to the copy. The existing agreement is not changed. The copy is saved when
build()is processed.The call itself only records the operation (see the type description). If no Rebate Agreement with the given unique name exists, the operations chained on the returned builder are skipped and no copy is created.
Example:
ratBuilder.fromExisting("RA-2026-Bonus") .submitAfterBuild() .build()- Parameters:
RAuniqueName- the unique name of the existing Rebate Agreement- Returns:
- a builder for the new Rebate Agreement
- See Also:
-
fromParams
Starts building a Rebate Agreement from parameters.When the recorded operations run, the application creates a new Rebate Agreement and sets each map entry as a field of the agreement. The new agreement is saved when
build()is processed.The call itself only records the operation (see the type description), so an invalid key is not reported at the point of this call. It is found only when the recorded operations run, and it rolls back the whole batch that contains this Rebate Agreement.
Example:
def builder = ratBuilder.fromParams([ "label" : "Annual Bonus 2027", "startDate" : api.parseDate("yyyy-MM-dd", "2027-01-01"), "endDate" : api.parseDate("yyyy-MM-dd", "2027-12-31"), "payoutDate": api.parseDate("yyyy-MM-dd", "2028-02-01"), ]) builder.build()- Parameters:
params- the header fields of the new Rebate Agreement, as a map of field name to value. The keys are field names of the Rebate Agreement, for examplelabel,startDate,endDate,payoutDate,targetDateoruniqueName. A key that is not a field of the Rebate Agreement rolls back the whole batch (see the type description).- Returns:
- a builder for the new Rebate Agreement
- See Also:
-
registerPlaceholder
Registers a placeholder that can later be applied withRATBuilder.RABuilder.applyPlaceholder(String, Object).A placeholder is a named value that the user who runs the template can map to fields of the Rebate Agreement. The registered placeholders are returned to the application after the logic runs, and the mapping chosen by the user decides which fields
RATBuilder.RABuilder.applyPlaceholder(String, Object)fills.Unlike the
RATBuilder.RABuildermethods, this method takes effect immediately: it adds the placeholder to the list returned byplaceholders(). It does not change any Rebate Agreement.Example:
ratBuilder.registerPlaceholder(InputType.USERENTRY, "discount") ratBuilder.fromParams(["label": "Annual Bonus 2027"]) .applyPlaceholder("discount", 0.05) .build()- Parameters:
type- the input type of the placeholdername- the placeholder name- Returns:
- itself
- See Also:
-
placeholders
List<RATPlaceholder> placeholders()Returns the placeholders registered so far withregisterPlaceholder(InputType, String), in the order of registration.This method only reads the list and does not record any operation. The returned list is the builder's own list, not a copy. Do not modify it; register placeholders with
registerPlaceholder(InputType, String)instead.Example:
ratBuilder.registerPlaceholder(InputType.USERENTRY, "discount") def count = ratBuilder.placeholders().size()- Returns:
- the registered placeholders; an empty list when none are registered, never
null - See Also:
-