tpm-promotion Component

The tpm-promotion LWC is a service component that loads a TPM promotion, exposing methods to update the promotion state, and events to keep all UI components of the promotion page in sync when the promotion state changes. This component is provided as part of the released managed package.

Here’s the event payload structure.

This event is triggered when a different area of the application is navigated to.

The possible values of area are:

  • PROMOTION_PLANNING: This area identifies the Promotion Planning UI.
  • PL_GRID: This area identifies the Promotion PL.

The possible values of section are:

  • PROMOTION: Promotion level components section.
  • TACTIC: Tactic level components section.

This event is triggered when the P&L filters are opened (true) or closed (false).

This event is triggered when the lifecycle state of the TPM promotion component changes. Status changes are triggered by lifecycle operations on the promotion record.

The possible values are:

  • LOADING: The promotion is being loaded.
  • VALID: The promotion is loaded and can be interacted with.
  • SAVING: The promotion is being saved to the database.
  • ERROR: An irrecoverable error has occurred.

This event is triggered when the promotion grids are calculated or recalculated.

The possible values are:

  • LOADING: The calculations are being processed, or the engine is loading.
  • VALID: The calculations are completed and values can be requested
  • ERROR: An irrecoverable error has occurred.
  • DISABLED: Calculations Engine is disabled for the promotion.

This event is triggered when the edit mode changes for the page.

This event is triggered when the focused tactic changes.

The possible values of are:

  • null: No focused tactic found.
  • A tactic ID: The ID of the focused tactic.

This event is triggered when the promotion attributes change.

The event value contains all the Promotion SObject attributes.

This event is triggered when the effective categories of the promotion change.

The event value contains an array of product IDs from the effective categories.

This event is triggered when the effective brands of the promotion change.

The event value contains an array of product IDs from the effective brands.

This event is triggered when the tactic attributes change.

The event value contains all the Tactic sObjects and their attributes.

This event is triggered when the Tactic fund properties change.

The event value contains all the Tactic Fund sObjects and their attributes.

This event is triggered when the properties of the Promotion Attachment link change.

Promotion attachment links are junction objects between a Promotion record and a Promotion Attachment Record.

The event value contains all the Promotion Attachment Link sObjects and their attributes.

This event is triggered when the properties of the Promotion Attachment sObject change.

Promotion Attachment records must be created before they can be linked to a promotion during the save process.

The event value contains all the Promotion Attachment Link sObjects and their attributes.

This event is triggered when the promotion categories change.

The event value is an array of Product2 IDs referencing Category records.

This event is triggered when the promotion sub-accounts change.

This event is triggered when the participating customers of a promotion change. The participating customers list is used to determine the customers the promotion is pushed to during the push process.

This event is triggered when the Tactic Condition Creation definitions for the tactics included in the promotion change.

The event value is an array of Tactic Condition Creation Definition sObject records and their attributes.

This event is triggered when the custom state changes. Custom State is a special area of the promotion state where customers can set their custom structures that are processed and committed in Salesforce at the same time as the promotion.

This event is triggered when the promotion products change.

The event value is an array of all promotion product IDs.

This event is triggered when the uplift prediction availability changes. It indicates if the feature is enabled for the promotion.

This event is triggered based on whether the uplift prediction can be performed on the current promotion or not. It indicates possible errors with the promotion state that prevent uplift prediction from being executed.

This event is triggered when the uplift prediction process state changes.

The possible values are:

  • RUNNING
  • IDLE

This event is triggered when the promotion manual inputs change. The event payload contains an array of TPMManualInput instances being used for the TPM Grids.

This event is triggered when the edit access rights in the Access Control List (ACL) changes for a promotion or tactic. This event notifies about an ACL change. Get the actual value of an edit access right element using the isVisible and isEditable methods of the tpm-promotion class.

This event is triggered when the promotion grids are calculated or recalculated, and validation KPIs are emitting error messages.

Here’s an example of how to use the tpm-promotion component to interact with a promotion:

Here are all the tpm-promotion methods.

  • exportKPIs

    This method returns a promise resolving to the values of the KPIs for the selected KPI subsets or names, levels, and period types.

  • duplicateTactic

    The method returns a promise resolving to a JavaScript object with all the tactic attributes preset.

  • generateTactic

    This method generates a Tactic record using the tacticTemplateId as a base. The method returns a promise resolving to a Javascript object with all the tactic attributes preset. After generating the tactic, it can be added to the promotion data by calling setTacticField for all the fields.

  • getProperty

    Imperatively retrieve promotion state properties.

  • getLevelNames

    This method returns a promise resolving to the list of levels that are currently loaded in the Calculation Engine. If the calculation status isn’t valid, the method returns an error.

  • getKPISubsets

    This method returns a promise resolving to the list of KPI Subsets that are currently loaded in the Calculation Engine. If the calculation status isn’t valid, the method returns an error.

  • getKPIs

    This method returns a promise resolving to the list of KPIs that are currently loaded in the Calculation Engine. If the calculation status isn’t valid, the method returns an error.

  • getPeriods

    This method returns a promise resolving to the list of Periods that are currently loaded in the Calculation Engine. If the calculation status isn’t valid, the method returns an error.

  • getPeriodTypes

    This method returns a promise resolving to the list of Period Types that are currently loaded in the Calculation Engine. If the calculation status isn’t valid, the method returns an error.

  • isEditable

    This method returns true if an EARight element is flagged as editable for the passed record ID.

  • isVisible

    This method returns true if an EARight element is flagged as visible for the passed record ID.

  • navigateTo

    Moves the page focus to the passed in target. The target object requires an area attribute and an optional section attribute:

  • push

    Begins the promotion push process. Saves the current state of the promotion SObject and all of its related SObjects.

  • reload

    Reloads the promotion SObject and all the related records.

  • removeCallback

    Remove already setup callback functions that will be called as part of method flows.

  • save

    Begins the promotion save process. Saves the current state of the promotion SObject and all of its related SObjects. I’ll also save the custom state. During the save process, the component will emit events to notify custom components about different events that might happen during the process.

  • close

    This process initiates the close promotion process. It sets the promotion phase to ToBeFinanciallyClosed and initiates the save process. This triggers the financial closure workflow in Processing Services, which handles the promotion’s accruals and final calculations. The method also saves the related SObjects and custom state.

  • selectTactic

    Sets the internally selected tactic to the passed in tactic ID.

  • setCallback

    Setup callback functions that will be called as part of method flows.

  • setCustomState

    This object will be sent along with the promotion information during save to SFDC in order to be processed and committed. Using the custom state, customers can set up additional data to send along the promotion data to be saved in the same transaction as the promotion. This custom state will be forwarded to the customized APEX class handling promotion save customizations..

  • setEditMode

    Sets the promotion into edit mode or exits edit mode.

  • setEditable

    This method sets the editability value of an EARight element for the given promotion or tactic record ID.

  • setVisible

    This method sets the visibility value of an EARight element for the given promotion, or tactic record ID. 

  • setParticipatingCustomers

    Lists the objects with the participating customers format.

  • setPLGridFilterOpen

    Displays or hides the P&L filter section on the promotion P&L view.

  • setPromotionAttachmentLinks

    Sets the related promotion attachment links to the promotion.

  • setPromotionAttachments

    Sets the related promotion attachments to the promotion. Promotion attachments cannot be created or deleted from the tpm-promotion component API. Promotion attachment records need to be previously created before linking them to a promotion with a promotion attachment link record.

  • setPromotionCategories

    Sets the list of categories of the promotion. TPM Application will only detect category changes after a reload.

  • setPromotionField

    Sets a promotion SObject field.

  • setPromotionManualInputs

    This method sets an array of manual inputs in the TPM promotion service component.

  • setSubAccounts

    Lists the objects with the SubAccounts format.

  • setTacticConditionCreationDefinitions

    Sets the related tactic condition creation definition records to the promotion.

  • setTacticField

    Sets the tactic SObject field.

  • setTacticFunds

    Sets the related tactic funds to the Promotion. To delete the tactic fund record, set the IsDeleted attribute to true. To flag a record as new, set the IsNew attribute to true. If the Sales Org has Fund Autodetermination enabled, TPM Application will always overwrite tactic funds with the records generated by the autodetermination process.

  • predictUplift

    This method returns a promise resolved when an uplift prediction is completed for the promotion. If the uplift prediction is disabled or the promotion isn’t in a correct status, the promise is rejected with an error stating the cause.

This method returns a promise resolving to the values of the KPIs for the selected KPI subsets or names, levels, and period types.

58.0

exportKPIs(options)

NameTypeDescriptionRequired or Optional
options.subsetsList<String>List of loaded KPI subsets to retrieve data from.
You can get a list of loaded subsets using the getKPISubsets() method.
Provide either the KPI subsets or the KPI names.
Optional
options.kpisList<String>List of KPI names to retrieve data from.
You can get a list of loaded KPI names using the getKPIs() method.
Provide either the KPI subsets or the KPI names.
Optional
options.levelsList<String>List of loaded levels to retrieve data from. 
You can get a list of loaded levels using the getLevelNames() method.
Optional
options.periodsList<String>List of loaded period types to retrieve data.
You can get a list of loaded period types using the getPeriodTypes() method.
Optional
options.formatList<String>Format in which the response is returned.
Possible formats are:
  • JSON: The response is an array of JavaScript objects.
  • Serialized: The response is a JSON string of JavaScript objects.
  • CSV: The response is a CSV string.

The default format is JSON.
Optional

The returned data is a list of rows (JavaScript objects or CSV rows). Each row represents the value of the KPI for the determined level. Each row contains values for all the periods specified in the request.

The method returns a promise resolving to a JavaScript object with all the tactic attributes preset.

This method generates a tactic record using the tacticId as a base. You can add the generated tactic record to the promotion data by calling setTacticField for all the fields.

60.0

duplicateTactic(tacticTemplateId)

tacticTemplateId: String. Record ID of the tactic template.

This method generates a Tactic record using the tacticTemplateId as a base. The method returns a promise resolving to a Javascript object with all the tactic attributes preset. After generating the tactic, it can be added to the promotion data by calling setTacticField for all the fields.

55

generateTactic(tacticTemplateId)

Imperatively retrieve promotion state properties.

55.0

getProperty(propName)

The available properties to retrieve are:

  • focusedArea
  • status
  • calculationStatus
  • editMode
  • selectedTacticId
  • promotion
  • tactics
  • tacticFunds
  • promotionAttachments
  • promotionAttachmentLinks
  • promotionCategories
  • productFilter
  • subAccounts
  • participatingCustomers
  • tacticConditionCreationDefinitions
  • upliftPredictionProcessStatus
  • upliftPredictionEnabled
  • upliftPredictionAvailable
  • promotionProducts
  • manualInputs
  • kpiValidations
  • customState

This method returns a promise resolving to the list of levels that are currently loaded in the Calculation Engine. If the calculation status isn’t valid, the method returns an error.

58.0

getLevelNames()

This method returns a promise resolving to the list of KPI Subsets that are currently loaded in the Calculation Engine. If the calculation status isn’t valid, the method returns an error.

58.0

getKPISubsets()

This method returns a promise resolving to the list of KPIs that are currently loaded in the Calculation Engine. If the calculation status isn’t valid, the method returns an error.

58.0

getKPIs()

This method returns a promise resolving to the list of Periods that are currently loaded in the Calculation Engine. If the calculation status isn’t valid, the method returns an error.

58.0

getPeriods()

This method returns a promise resolving to the list of Period Types that are currently loaded in the Calculation Engine. If the calculation status isn’t valid, the method returns an error.

58.0

getPeriodTypes()

This method returns true if an EARight element is flagged as editable for the passed record ID.

The record ID must be a promotion ID or a tactic ID.

60.0

isEditable(recordId, eaRight)

This method returns true if an EARight element is flagged as visible for the passed record ID.

The record ID must be a promotion ID or a tactic ID.

60.0

isVisible(recordId, eaRight)

Moves the page focus to the passed in target. The target object requires an area attribute and an optional section attribute:

55

navigateTo(target)

Begins the promotion push process. Saves the current state of the promotion SObject and all of its related SObjects.

55

push()

Reloads the promotion SObject and all the related records.

55

reload()

Remove already setup callback functions that will be called as part of method flows.

55

removeCallback(event, callback)

Begins the promotion save process. Saves the current state of the promotion SObject and all of its related SObjects. I’ll also save the custom state. During the save process, the component will emit events to notify custom components about different events that might happen during the process.

55

save()

This process initiates the close promotion process. It sets the promotion phase to ToBeFinanciallyClosed and initiates the save process. This triggers the financial closure workflow in Processing Services, which handles the promotion’s accruals and final calculations. The method also saves the related SObjects and custom state.

Promotion Closure should be enabled in the Promotion Template before using this method.

65

close()

During the close promotion process, the TPM component notifies custom components about different events that might happen during the process. Before using the close promotion method, you must set a callback using the setCallback(event, callback) method. During the close promotion process, the following callbacks are executed:

  • onBeforeSave: Executes before the promotion saves to SFDC.
  • onAfterSave: Executes after the promotion saves to SFDC.
  • onAfterSync: Executes after the promotion synchronizes to Processing Services.
  • onError: Executes if any error occurs during all the close steps.

In the callback function, it’s possible to return a promise. If it returns a promise, the process pauses until the promise is resolved. If the promise is resolved correctly, the next step continues. If the promise is rejected, it is treated as an error and the onError callback is executed.

Sets the internally selected tactic to the passed in tactic ID.

55

selectTactic(tacticId)

Setup callback functions that will be called as part of method flows.

55

setCallback(tacticFunds)

This object will be sent along with the promotion information during save to SFDC in order to be processed and committed. Using the custom state, customers can set up additional data to send along the promotion data to be saved in the same transaction as the promotion. This custom state will be forwarded to the customized APEX class handling promotion save customizations..

55

setCustomState(customState)

Sets the promotion into edit mode or exits edit mode.

55

setEditMode(value)

This method sets the editability value of an EARight element for the given promotion or tactic record ID.

After the editability value of an EARight element is set for the record, the promotion UI is re-rendered to reflect the changes. But, after you save the promotion, the EARight elements are reset to the initial values provided by TPM and the customization hook.

60.0

setEditable(recordId, eaRight, value)

  • recordId: ID of a promotion or tactic
  • eaRight: An EARight element
  • value: A boolean value

This method sets the visibility value of an EARight element for the given promotion, or tactic record ID. 

After the EARight element visibility value is set for a record, the promotion UI is re-rendered to reflect the changes. But, after you save the promotion, the EARight elements are reset to the initial values provided by TPM and the customization hook.

60.0

setVisible(recordId, eaRight, value)

  • recordId: ID of a promotion or tactic
  • eaRight: An EARight element
  • value: A Boolean value

Lists the objects with the participating customers format.

55

setParticipatingCustomers(participatingCustomers)

Displays or hides the P&L filter section on the promotion P&L view.

55

setPLGridFilterOpen(value)

Sets the related promotion attachment links to the promotion.

55

setPromotionAttachmentLinks(attachmentLinks)

Sets the related promotion attachments to the promotion. Promotion attachments cannot be created or deleted from the tpm-promotion component API. Promotion attachment records need to be previously created before linking them to a promotion with a promotion attachment link record.

55

setPromotionAttachments(attachments)

Sets the list of categories of the promotion. TPM Application will only detect category changes after a reload.

55

setPromotionCategories(categories)

Sets a promotion SObject field.

55

setPromotionField(field, value)

The field value sets that are managed by KPI Maps are ignored if provided through Business Objects API. This behaviour prevents any outdated data being sent to Trade Promotion Management.

This method sets an array of manual inputs in the TPM promotion service component.

Manual grid edits are an array of TPMManualInput instances. You can add new entries, or remove entries from the existing array of elements.

60.0

setPromotionManualInputs(manualInputs)

Lists the objects with the SubAccounts format.

55

setSubAccounts(subAccounts)

Sets the related tactic condition creation definition records to the promotion.

55

setTacticConditionCreationDefinitions(tacticConditionCreationDefinitions)

Sets the tactic SObject field.

55

setTacticField(tacticId, field, value)

The field value sets that are managed by KPI Maps are ignored if provided through Business Objects API. This behaviour prevents any outdated data being sent to Trade Promotion Management.

Sets the related tactic funds to the Promotion. To delete the tactic fund record, set the IsDeleted attribute to true. To flag a record as new, set the IsNew attribute to true. If the Sales Org has Fund Autodetermination enabled, TPM Application will always overwrite tactic funds with the records generated by the autodetermination process.

55

setTacticFunds(tacticFunds)

The field value sets that are managed by KPI Maps are ignored if provided through Business Objects API. This behaviour prevents any outdated data being sent to Trade Promotion Management.

This method returns a promise resolved when an uplift prediction is completed for the promotion. If the uplift prediction is disabled or the promotion isn’t in a correct status, the promise is rejected with an error stating the cause.

58.0

predictUplift()