---
schema_version: "1"
id: 4e65e7faff49bb371678a1d8dc1f7b7da6d9577cca984b582f6d7764c7ffe1e7
title: tpm-promotion Component
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/retail_api/tpm_promotion_component_referance.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/tpm_promotion_component_referance.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 02bf1635c465a22f902a67a3483bca8628d64edd006b14e46710880084f39493
description: 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 are all the tpm-promotion methods.This method returns a promise resolving to the values of the KPIs for the selected KPI subsets or names, levels, and period types.The method returns a promise resolving to a JavaScript object with all the tactic attributes preset.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. Imperatively retrieve promotion state properties.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.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.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.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.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.This method returns true if an EARight element is flagged as editable for the passed record ID.This method returns true if an EARight element is flagged as visible for the passed record ID.Moves the page focus to the passed in target. The target object requires an area attribute and an optional section attribute:Begins the promotion push process. Saves the current state of the promotion SObject and all of its related SObjects. Reloads the promotion SObject and all the related records.Remove already setup callback functions that will be called as part of method flows. 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. 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.Sets the internally selected tactic to the passed in tactic ID.Setup callback functions that will be called as part of method flows.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..Sets the promotion into edit mode or exits edit mode.This method sets the editability value of an EARight element for the given promotion or tactic record ID.This method sets the visibility value of an EARight element for the given promotion, or tactic record ID. Lists the objects with the participating customers format.Displays or hides the P&L filter section on the promotion P&L view.Sets the related promotion attachment links to the promotion.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. Sets the list of categories of the promotion. TPM Application will only detect category changes after a reload. Sets a promotion SObject field.This method sets an array of manual inputs in the TPM promotion service component.Lists the objects with the SubAccounts format.Sets the related tactic condition creation definition records to the promotion.Sets the tactic SObject field.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. 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.
---
# 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.

## Namespace

cgcloud

## Events

Here’s the event payload structure.

{
    detail : {
        value: <<new value of the property>>,
        property: <<property name>>,
        recordId: <<promotionId>>
    }
}

## onfocusedareachange

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

{
    detail: {
        value: {
            area: 'PROMOTION\_PLANNING',
            section: 'PROMOTION'
        },
        property: 'focusedArea',
        promotionId: 'a2WTC0000000F772AE'
    }
}

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.

## onisplgridfilteropenchange

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

{
    detail : {
        value: true,
        property: 'isPLGridFilterOpen',
        promotionId: 'a2WTC0000000F772AE'
    }
}

## onstatuschange

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.

{
    detail : {
        value: 'VALID',
        property: 'status',
        promotionId: 'a2WTC0000000F772AE'
    }
}

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.

## oncalculationstatuschange

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

{
    detail : {
        value: 'LOADING',
        property: 'calculationStatus',
        promotionId: 'a2WTC0000000F772AE'
    }
}

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.

## oneditmodechange

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

{
    detail : {
        value: true,
        property: 'editMode',
        promotionId: 'a2WTC0000000F772AE'
    }
}

## onselectedtacticidchange

This event is triggered when the focused tactic changes.

{
    detail : {
        value: 'a37TC00000014j8YAA',
        property: 'tacticId',
        promotionId: 'a2WTC0000000F772AE'
    }
}

The possible values of are:

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

## onpromotionchange

This event is triggered when the promotion attributes change.

The event value contains all the Promotion SObject attributes.

{
    detail : {
        value: {
            IsNew: false, // Flag to indicate if the record is new
            IsDeleted: false, // Flag to indicate if the record is deleted
            Id : 'a2WTC0000000F772AE', // Record id
            cgcloud\_\_Slogan\_\_c: 'Sample Promotion' // Record attribute. 
            // All Promotion record fields will be present as attributes
        },
        property: 'promotion',
        promotionId: 'a2WTC0000000F772AE'
    }
}

## oneffectivecategorieschange

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.

{
    detail : {
        value: \[ // Array of Category product IDs
            "01t17000001siy5AAA"
        \],
        property: 'effectiveCategories',
        promotionId: 'a2WTC0000000F772AE'
    }
}

## oneffectivebrandschange

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.

{
    detail : {
        value: \[ // Array of Brand product IDs
            "01t17000001siy5AAA"
        \],
        property: 'effectiveBrands',
        promotionId: 'a2WTC0000000F772AE'
    }
}

## ontacticschange

This event is triggered when the tactic attributes change.

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

{
    detail : {
        value: \[ // An array of objects
            {
                IsNew: false, // Flag to indicate if the record is new
                IsDeleted: false, // Flag to indicate if the record is deleted
                Id : 'a37TC00000014j8YAA', // Record ID
                cgcloud\_\_Comment\_\_c: 'Sample Tactic', // Record attribute. 
                // All tactic record fields will be present as attributes
                ...
                // Additional Fields
                ProductFilter: {...}, // contains the Tactic Product Filter
                EffectiveCategories: \[...\], // List of effective categories for the tactic
                EffectiveBrands: \[...\] // List of effective brands for the tactic 
                },
            ...
        \],
        property: 'tactics',
        promotionId: 'a2WTC0000000F772AE'
    }
}

## ontacticfundschange

This event is triggered when the Tactic fund properties change.

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

{
    detail : {
        value: \[ // An array of objects
            {
                IsNew: false, // Flag to indicate if the record is new
                IsDeleted: false, // Flag to indicate if the record is deleted
                Id : 'a38TC00000014j8YAA', // Record ID
                cgcloud\_\_Fund\_\_c: 'a39TC00000014j8YAA', // Record attribute. Reference to the Fund\_\_c record
                cgcloud\_\_Tactic\_\_c: 'a37TC00000014j8YAA', // Record attribute. Reference to the Tactic\_\_c record
                // All Tactic Fund record fields will be present as attributes
                ...
            },
            ...
        \],
        property: 'tacticFunds',
        promotionId: 'a2WTC0000000F772AE'
    }
}

## onpromotionattachmentlinkschange

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.

{
    detail : {
        value: \[ // An array of objects
            {
                IsNew: false, // Flag to indicate if the record is new
                IsDeleted: false, // Flag to indicate if the record is deleted
                Id : 'a40TC00000014j8YAA', // Record ID
                cgcloud\_\_Promotion\_Attachment\_\_c: 'a41TC00000014j8YAA', // Record attribute. Reference to the Promotion\_Attachment\_\_c record
                // All Tactic Fund record fields will be present as attributes
                ...
            },
            ...
        \],
        property: 'promotionAttachmentLinks',
        promotionId: 'a2WTC0000000F772AE'
    }
}

## onpromotionattachmentschange

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.

{
    detail : {
        value: \[ // An array of objects
            {
                IsNew: false, // Flag to indicate if the record is new. Promotion attachments cannot be flagged as new
                IsDeleted: false, // Flag to indicate if the record is deleted. Promotion attachments cannot be flagged as deleted
                Id : 'a41TC00000014j8YAA', // Record ID
                cgcloud\_\_Description\_Language\_1\_\_c: 'Sample Attachment', // Record attribute. Reference to the Promotion\_Attachment\_\_c record
                // All Tactic Fund record fields will be present as attributes
                ...
            },
            ...
        \],
        property: 'promotionAttachments',
        promotionId: 'a2WTC0000000F772AE'
    }
}

## onpromotioncategorieschange

This event is triggered when the promotion categories change.

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

{
    detail : {
        value: \[ "01t17000001siy5AAA" \],
        property: 'promotionCategories',
        promotionId: 'a2WTC0000000F772AE'
    }
}

## onsubaccountschange

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

{
    detail : {
        value: \[ // Array of items
            {
                "volume": 50, // Percent of volume for this sub account. Sum of included sub accounts volume must be 100 or less
                "included": true, // Is Included?
                "externalid": "Supermarkets" // External id of the SubAccount
            }
        \],
        property: 'subAccounts',
        recordId: 'a2WTC0000000F772AE'
    }
}

## onparticipatingcustomerschange

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.

{
    detail : {
        value: \[ // Array of items
            {
                "included": true, // Is Included?
                "externalid": "Supermarkets" // External id of the Participating Customer
            }
        \],
        property: 'participatingCustomers',
        promotionId: 'a2WTC0000000F772AE'
    }
}

## ontacticconditioncreationdefinitionschange

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.

{
    detail : {
        value: \[ // An array of objects
            {
                IsNew: false, // Flag to indicate if the record is new
                IsDeleted: false, // Flag to indicate if the record is deleted
                Id : 'a50TC00000014j8YAA', // Record id
                cgcloud\_\_Tactic\_\_c: 'a37TC00000014j8YAA', // Record attribute. 
                // All Tactic condition creation definition record fields will be present as attributes
                ...
            },
            ...
        \],
        property: 'tacticConditionCreationDefinitions',
        promotionId: 'a2WTC0000000F772AE'
    }
}

## oncustomstatechange

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.

{
    detail : {
        value: {...} // Custom object
        property: 'customState',
        promotionId: 'a2WTC0000000F772AE'
    }
}

## onpromotionproductschange

This event is triggered when the promotion products change.

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

{
    detail : {
        value: \[
            '00X000000000000AAA'
        \],
        property: 'promotionProducts',
        promotionId: 'a2WTC0000000F772AE'
    }
}

## onupliftpredictionavailablechange

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

{
    detail : {
        value: {
            available: true
            kpi: "PredictedUplift"
        },
        property: 'upliftPredictionAvailable',
        promotionId: 'a2WTC0000000F772AE'
    }
}

## onupliftpredictionenabledchange

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.

{
    detail : {
        value: {
           enabled: false, 
           reasons: \[
               "No Uplift Prediction KPI is defined."
           \]
        },
        property: 'upliftPredictionEnabled',
        promotionId: 'a2WTC0000000F772AE'
    }
}

## onupliftpredictionprocessstatuschange

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

The possible values are:

- RUNNING
- IDLE

{
    detail : {
        value: "RUNNING",
        property: 'upliftPredictionProcessStatus',
        promotionId: 'a2WTC0000000F772AE'
    }
}

## onmanualinputschange

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.

{
    detail : {
        value: \[
            {}, // TPMManualInput instance
            {}  // TPMManualInput instance
        \],
        property: 'manualInputs',
        recordId: 'a2WTC0000000F772AE'
    }
}

## onaclchange

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.

{
    detail : {
        property: 'acl',
        recordId: 'a2WTC0000000F772AE'
    }
}

## onkpivalidationschanges

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

{
    detail : {
        value: {
            errorAmount: 1, // Total number of errors
            errorMessages: \[ // Sample of messages
                {
                     productid: '01tXXXXXXXXXXXXXXX', // Product
                     productgroupid: '01tYYYYYYYYYYYYYYY', // Product Group
                     kpiname: 'TEST', // Name of the KPI
                     values: \[
                        1,
                        2
                     \],
                     tacticid: 'aaa000000000000000', // Tactic Id
                     weeklabel: '03/2023' // Period label
                }
            \]
        },
        property: 'calculationStatus',
        recordId: 'a2WTC0000000F772AE'
    }
}

## Example Implementation

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

// myComponent.html
<template>
    <!-- Instantiate a tpm-promotion component to bridge -->
    <!-- with the Promotion state  -->
    <cgcloud-tpm-promotion 
        promotion-id={recordId}
        onpromotionchange={onPromotionChange}
        oneditmodechange={onEditModeChange}>
    </cgcloud-tpm-promotion>

    <!-- Create a card component with a Form item to allow a field -->
    <!-- to be editable, this field will be aligned to page edit mode -->
    <lightning-card  title="My Card">
        <lightning-record-form
            object-api-name="cgcloud\_\_Promotion\_\_c"
            record-type-id={myRecordTypeId} <!-- Used to load field specific metadata -->
        >
            <lightning-input-field 
                field-name="MyPromotionField\_\_c"
                disabled={notInEditMode}
                value={myPromotionFieldValue}
                onchange={onFieldValueChange}
            ></lightning-input-field>
        </lightning-record-form>
    </lightning-card>
</template>

import { LightningElement, api } from 'lwc';

export default class SampleTpmPromotionDetails extends LightningElement {
    // Required to get the promotion id of the page
    @api recordId;
    
    notInEditMode = false;
    myPromotionFieldValue = '';
    myRecordTypeId = '';

    // Executed every time the editMode changes for the promotion
    // Field will be editable if in Edit mode
    onEditModeChange(event) {
        this.notInEditMode = !event.detail.value;
    }

    // Executed every time the promotion value changes 
    onPromotionChange(event) {
        this.myPromotionFieldValue = event.detail.value\['MyPromotionField\_\_c'\];
        this.myRecordTypeId = event.detail.value\['RecordTypeId'\];
    }

    // Executed when the editable field changes
    onFieldValueChange(event) {
        // Get the tpm-promotion component
        const component = this.template.querySelector('cgcloud-tpm-promotion');
        
        // Update the promotion state with the new field value
        component.setPromotionField(
           'MyPromotionField\_\_c',
           event.detail.value
        );     
}

- **[tpm-promotion Component Methods](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/tpm_promotion_component_referance.htm#tpm-promotionComponentReference_method)**  
    Here are all the tpm-promotion methods.

## tpm-promotion Component Methods

Here are all the tpm-promotion methods.

- **[exportKPIs](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/tpm_promotion_component_referance.htm#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](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/tpm_promotion_component_referance.htm#duplicateTactic)**  
    The method returns a promise resolving to a JavaScript object with all the tactic attributes preset.
- **[generateTactic](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/tpm_promotion_component_referance.htm#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](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/tpm_promotion_component_referance.htm#getProperty)**  
    Imperatively retrieve promotion state properties.
- **[getLevelNames](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/tpm_promotion_component_referance.htm#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](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/tpm_promotion_component_referance.htm#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](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/tpm_promotion_component_referance.htm#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](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/tpm_promotion_component_referance.htm#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](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/tpm_promotion_component_referance.htm#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](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/tpm_promotion_component_referance.htm#isEditable)**  
    This method returns true if an EARight element is flagged as editable for the passed record ID.
- **[isVisible](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/tpm_promotion_component_referance.htm#isVisible)**  
    This method returns true if an EARight element is flagged as visible for the passed record ID.
- **[navigateTo](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/tpm_promotion_component_referance.htm#navigateto)**  
    Moves the page focus to the passed in target. The target object requires an area attribute and an optional section attribute:
- **[push](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/tpm_promotion_component_referance.htm#push)**  
    Begins the promotion push process. Saves the current state of the promotion SObject and all of its related SObjects.
- **[reload](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/tpm_promotion_component_referance.htm#reload)**  
    Reloads the promotion SObject and all the related records.
- **[removeCallback](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/tpm_promotion_component_referance.htm#removeCallback)**  
    Remove already setup callback functions that will be called as part of method flows.
- **[save](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/tpm_promotion_component_referance.htm#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](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/tpm_promotion_component_referance.htm#closePromotion)**  
    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](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/tpm_promotion_component_referance.htm#selectTactic)**  
    Sets the internally selected tactic to the passed in tactic ID.
- **[setCallback](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/tpm_promotion_component_referance.htm#setCallback)**  
    Setup callback functions that will be called as part of method flows.
- **[setCustomState](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/tpm_promotion_component_referance.htm#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](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/tpm_promotion_component_referance.htm#setEditMode)**  
    Sets the promotion into edit mode or exits edit mode.
- **[setEditable](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/tpm_promotion_component_referance.htm#setEditable)**  
    This method sets the editability value of an EARight element for the given promotion or tactic record ID.
- **[setVisible](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/tpm_promotion_component_referance.htm#setVisible)**  
    This method sets the visibility value of an EARight element for the given promotion, or tactic record ID.
- **[setParticipatingCustomers](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/tpm_promotion_component_referance.htm#setParticipatingCustomers)**  
    Lists the objects with the participating customers format.
- **[setPLGridFilterOpen](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/tpm_promotion_component_referance.htm#setPLGridFilterOpen)**  
    Displays or hides the P&L filter section on the promotion P&L view.
- **[setPromotionAttachmentLinks](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/tpm_promotion_component_referance.htm#setPromotionAttachmentLinks)**  
    Sets the related promotion attachment links to the promotion.
- **[setPromotionAttachments](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/tpm_promotion_component_referance.htm#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](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/tpm_promotion_component_referance.htm#setPromotionCategories)**  
    Sets the list of categories of the promotion. TPM Application will only detect category changes after a reload.
- **[setPromotionField](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/tpm_promotion_component_referance.htm#setPromotionField)**  
    Sets a promotion SObject field.
- **[setPromotionManualInputs](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/tpm_promotion_component_referance.htm#setPromotionManualInputs)**  
    This method sets an array of manual inputs in the TPM promotion service component.
- **[setSubAccounts](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/tpm_promotion_component_referance.htm#setSubAccounts)**  
    Lists the objects with the SubAccounts format.
- **[setTacticConditionCreationDefinitions](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/tpm_promotion_component_referance.htm#setTacticConditionCreationDefinitions)**  
    Sets the related tactic condition creation definition records to the promotion.
- **[setTacticField](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/tpm_promotion_component_referance.htm#setTacticField)**  
    Sets the tactic SObject field.
- **[setTacticFunds](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/tpm_promotion_component_referance.htm#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](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/tpm_promotion_component_referance.htm#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.

### exportKPIs

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

#### API Version

58.0

#### Signature

exportKPIs(options)

#### Properties

<table class="featureTable sort_table" summary="">




                <thead class="thead sorted" align="left">
                  <tr>
                    <th class="featureTableHeader vertical-align-top " id="d42645e1065">Name</th>

                    <th class="featureTableHeader vertical-align-top " id="d42645e1068">Type</th>

                    <th class="featureTableHeader vertical-align-top " id="d42645e1071">Description</th>

                    <th class="featureTableHeader vertical-align-top " id="d42645e1074">Required or Optional</th>

                  </tr>

                </thead>

                <tbody class="tbody">
                  <tr>
                    <td class="entry" headers="d42645e1065" data-title="Name"><samp class="codeph nolang">options.subsets</samp></td>

                    <td class="entry" headers="d42645e1068" data-title="Type">List&lt;String&gt;</td>

                    <td class="entry" headers="d42645e1071" data-title="Description">List of loaded KPI subsets to retrieve data from. <p class="p">You can get
                        a list of loaded subsets using the <samp class="codeph nolang">getKPISubsets()</samp> method.</p>
                      <p class="p">Provide either the
                        KPI subsets or the KPI names.</p>
                    </td>

                    <td class="entry" headers="d42645e1074" data-title="Required or Optional">Optional </td>

                  </tr>

                  <tr>
                    <td class="entry" headers="d42645e1065" data-title="Name"><samp class="codeph nolang">options.kpis</samp></td>

                    <td class="entry" headers="d42645e1068" data-title="Type">List&lt;String&gt;</td>

                    <td class="entry" headers="d42645e1071" data-title="Description">List of KPI names to retrieve data from.<p class="p">You can get a list of
                        loaded KPI names using the <samp class="codeph nolang">getKPIs()</samp> method.</p>
                      <p class="p">Provide either the KPI
                        subsets or the KPI names.</p>
                    </td>

                    <td class="entry" headers="d42645e1074" data-title="Required or Optional">Optional </td>

                  </tr>

                  <tr>
                    <td class="entry" headers="d42645e1065" data-title="Name"><samp class="codeph nolang">options.levels</samp></td>

                    <td class="entry" headers="d42645e1068" data-title="Type">List&lt;String&gt;</td>

                    <td class="entry" headers="d42645e1071" data-title="Description">List of loaded levels to retrieve data from.&nbsp;<p class="p">You can get a
                        list of loaded levels using the <samp class="codeph nolang">getLevelNames()</samp> method.</p>
                    </td>

                    <td class="entry" headers="d42645e1074" data-title="Required or Optional">Optional</td>

                  </tr>

                  <tr>
                    <td class="entry" headers="d42645e1065" data-title="Name"><samp class="codeph nolang">options.periods</samp></td>

                    <td class="entry" headers="d42645e1068" data-title="Type">List&lt;String&gt;</td>

                    <td class="entry" headers="d42645e1071" data-title="Description">List of loaded period types to retrieve data. <p class="p">You can get a
                        list of loaded period types using the <samp class="codeph nolang">getPeriodTypes()</samp>
                        method.</p>
                    </td>

                    <td class="entry" headers="d42645e1074" data-title="Required or Optional">Optional</td>

                  </tr>

                  <tr>
                    <td class="entry" headers="d42645e1065" data-title="Name"><samp class="codeph nolang">options.format</samp></td>

                    <td class="entry" headers="d42645e1068" data-title="Type">List&lt;String&gt;</td>

                    <td class="entry" headers="d42645e1071" data-title="Description">Format in which the response is returned. <p class="p">Possible formats
                        are:</p>
                      <ul class="ul bulletList">
                        <li class="li">JSON: The response is an array of JavaScript objects.</li>

                        <li class="li">Serialized: The response is a JSON string of JavaScript
                          objects.</li>

                        <li class="li">CSV: The response is a CSV string.</li>

                      </ul>
                      <p class="p">The default format is JSON.</p>
                    </td>

                    <td class="entry" headers="d42645e1074" data-title="Required or Optional">Optional</td>

                  </tr>

                </tbody>

              </table>

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.

#### Example Implementation

const api = this.template.querySelector('cgcloud-tpm-promotion');

// Export options, the possible values can be extracted using
// the other described methods
const exportOptions = {
    subsets: \["Planning"\], // Subsets to request data
    periods: \[
        "Total",
        "Week"
    \],
    levels: \[
        "Total",
        "Category",
        "Product"
    \],
    format: "json"
};

// Correct Scenario
api.getProperty('calculationStatus'); // 'VALID'

api.exportKPIs(exportOptions)
    .then((data) => {
        // Example response as CSV
        //
        // kpiName,Category,Product,AP\_LBL\_TOTAL,03/2022,04/2022
        // SampleKPI1,,,246,123,123
        // SampleKPI1,01tTC0000000001AAA,,246,123,123
        // SampleKPI1,01tTC0000000001AAA,01tTC0000000002AAA,246,123,123
        // SampleKPI2,,,1974,987,987
        // SampleKPI2,01tTC0000000001AAA,,1974,987,987
        // SampleKPI2,01tTC0000000001AAA,01tTC0000000002AAA,1974,987,987
        
        // Example response as JSON
        //
        // \[{
        //    kpiName: "SampleKPI1",
        //    Category: null,
        //    Product: null,
        //    AP\_LBL\_TOTAL: 246,
        //    "03/2022": 123,
        //    "04/2022": 123     
        // }, {
        //    kpiName: "SampleKPI1",
        //    Category: "01tTC0000000001AAA",
        //    Product: null,
        //    AP\_LBL\_TOTAL: 246,
        //    "03/2022": 123,
        //    "04/2022": 123
        // },{
        //    kpiName: "SampleKPI1",
        //    Category: "01tTC0000000001AAA",
        //    Product: "01tTC0000000002AAA",
        //    AP\_LBL\_TOTAL: 246,
        //    "03/2022": 123,
        //    "04/2022": 123
        // },{
        //    kpiName: "SampleKPI2",
        //    Category: null,
        //    Product: null,
        //    AP\_LBL\_TOTAL: 1974,
        //    "03/2022": 987,
        //    "04/2022": 987
        // },{
        //    kpiName: "SampleKPI2",
        //    Category: "01tTC0000000001AAA",
        //    Product: null,
        //    AP\_LBL\_TOTAL: 1974,
        //    "03/2022": 987,
        //    "04/2022": 987
        // },{
        //    kpiName: "SampleKPI2",
        //    Category: "01tTC0000000001AAA",
        //    Product: "01tTC0000000002AAA",
        //    AP\_LBL\_TOTAL: 1974,
        //    "03/2022": 987,
        //    "04/2022": 987
        // }\]
        
        
        // We can access the properties on the result:
        const firstRecord = data\[0\];
        
        console.log(firstRecord\["kpiName"\]); // "SampleKPI1"
        // Since we request the total period, 
        // we can read the total period value
        console.log(firstRecord\["AP\_LBL\_TOTAL"\]); // 246
        // We can also read specific periods information
        console.log(firstRecord\["03/2022"\]); // 123
        // We can also know which level the row references 
        console.log(firstRecord\["Category"\]); // null
        console.log(firstRecord\["Product"\]); // null
        // Since Category is null, it means this data row 
        // represents the total value for KPI "SampleKPI1" 
        
        // For last record
        const lastRecord = data\[data.length - 1\];
        
        console.log(lastRecord\["kpiName"\]); // "SampleKPI2"
        // Since we request the total period, 
        // we can read the total period value
        console.log(lastRecord\["AP\_LBL\_TOTAL"\]); // 1974
        // We can also read specific periods information
        console.log(lastRecord\["03/2022"\]); // 987
        // We can also know which level the row references 
        console.log(lastRecord\["Category"\]); // "01tTC0000000001AAA"
        console.log(lastRecord\["Product"\]); // "01tTC0000000002AAA"
        // Since Product is not null, it means this data row 
        // represents the value for KPI "SampleKPI2" for that
        // specific product
    });

// Error Scenario
api.getProperty('calculationStatus'); // 'LOADING'

api.exportKPIs(exportOptions)
    .catch((error) => {
        console.log(error.message); // CalculationStatus is not "VALID". Current Status "LOADING"
    });

### duplicateTactic

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.

#### API Version

60.0

#### Signature

duplicateTactic(tacticTemplateId)

tacticTemplateId: String. Record ID of the tactic template.

#### Example Implementation

component.duplicateTactic('a43TC00000014j8YAA') // tactic ID as a parameter
    .then((tactic) => {
        // Add the tactic to the promotion component
        Object.keys(tactic).forEach((key) => {
            component.setTacticField(tactic.Id, key, tactic\[key\]);
        });
    });

### 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.

#### API Version

55

#### Signature

generateTactic(tacticTemplateId)

#### Example Implementation

component.generateTactic('a43TC00000014j8YAA') // tactic Id as parameter
    .then((tactic) => {
        // Add the tactic to the Promotion component
        Object.keys(tactic).forEach((key) => {
            component.setTacticField(tactic.Id, key, tactic\[key\]);
        });
    });

### getProperty

Imperatively retrieve promotion state properties.

#### API Version

55.0

#### Signature

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

#### Example Implementation

component.getProperty('promotion');

// Returns a Javascript object with attributes mapped to all promotion SObject
// attributes
// {
//     IsNew: false, // Flag to indicate if the record is new
//     IsDeleted: false, // Flag to indicate if the record is deleted
//     Id : 'a2WTC0000000F772AE', // Record id
//     cgcloud\_\_Slogan\_\_c: 'Sample Promotion', // Record attribute. 
//     // All Promotion record fields will be present as attributes
//     ...
// }

### 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.

#### API Version

58.0

#### Signature

getLevelNames()

#### Example Implementation

const api = this.template.querySelector('cgcloud-tpm-promotion');

// Correct Scenario
api.getProperty('calculationStatus'); // 'VALID'

api.getLevelNames()
    .then((levels) => {
        console.log(levels); // \["Tactic", "Category", "Brand", "Product"\]
    });

### 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.

#### API Version

58.0

#### Signature

getKPISubsets()

#### Example Implementation

const api = this.template.querySelector('cgcloud-tpm-promotion');
// Correct Scenario
api.getProperty('calculationStatus'); // 'VALID'

api.getKPISubsets()
    .then((subsets) => {
        console.log(subsets); // \["Planning", "VPC", "SPC", "PromoUI", …\]
    });

### 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.

#### API Version

58.0

#### Signature

getKPIs()

#### Example Implementation

const api = this.template.querySelector('cgcloud-tpm-promotion');

// Correct Scenario
api.getProperty('calculationStatus'); // 'VALID'

api.getKPIs()
    .then((kpis) => {
        // 0 
        console.log(kpis\[0\].id); // "0"
        console.log(kpis\[0\].name); // "BasePrice"
        console.log(kpis\[0\].kpitype); // "promotion"
        console.log(kpis\[0\].skipped); // \["Tactic"\]
        console.log(kpis\[0\].type); // "read"
        console.log(kpis\[0\].valuetype); // "Price"
    });

### 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.

#### API Version

58.0

#### Signature

getPeriods()

#### Example Implementation

const api = this.template.querySelector('cgcloud-tpm-promotion');

// Correct Scenario
api.getProperty('calculationStatus'); // 'VALID'

api.getPeriods()
    .then((periods) => {
        // 0 
        console.log(periods\[0\].id); // "0"
        console.log(periods\[0\].name); // "AP\_LBL\_TOTAL" (label of the period)
        console.log(periods\[0\].periodtype); // "Total"
        console.log(periods\[0\].dateFrom); // null
        console.log(periods\[0\].dateThru); // null
        // 1 
        console.log(periods\[1\].id); // 1
        console.log(periods\[1\].name); // "36/2022" // label in case of label is specified alternativly it returns the ....
        console.log(periods\[1\].periodtype); // "Week"
        console.log(periods\[1\].dateFrom); // 1661731200000 timestamp
        console.log(periods\[1\].dateThru); // 1662249600000 timestamp
    });

### 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.

#### API Version

58.0

#### Signature

getPeriodTypes()

#### Example Implementation

const api = this.template.querySelector('cgcloud-tpm-promotion');

// Correct Scenario
api.getProperty('calculationStatus'); // 'VALID'

api.getPeriodTypes()
    .then((periodTypes) => {
        console.log(periodTypes); // \["Total", "Week"\]
    });

### isEditable

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.

#### API Version

60.0

#### Signature

isEditable(recordId, eaRight)

### isVisible

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.

#### API Version

60.0

#### Signature

isVisible(recordId, eaRight)

### navigateTo

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

#### API Version

55

#### Signature

navigateTo(target)

#### Example Implementation

component.navigateTo({
    area: 'PROMOTION\_PLANNING',
    section: 'PROMOTION'
});

// After executing, the TPM UI will navigate to the Promotion Planning Promotion area

### push

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

#### API Version

55

#### Signature

push()

#### Example Implementation

// Create callback functions
const onBeforeSaveCallback = (data) => console.log('onBeforeSave', data.operation === 'push');
const onAfterSaveCallback = (data) => console.log('onAfterSave', data.operation === 'push');
const onAfterPushCallback = () => console.log('onAfterPush');
const onErrorCallback = (error) => console.log('onError', error);

// Setup callback functions
component.setCallback('onBeforeSave', onBeforeSaveCallback);
component.setCallback('onAfterSave', onAfterSaveCallback);
component.setCallback('onAfterPush', onAfterPushCallback);
component.setCallback('onError', onErrorCallback);

component.push();

// If the promotion is not pushable, onErrorCallback will be executed with an error message

// onBeforeSaveCallback is executed
// Data is saved to SFDC
// onAfterSaveCallback is executed
// Promotion Push process is scheduled
// onAfterPushCallback is executed

### reload

Reloads the promotion SObject and all the related records.

#### API Version

55

#### Signature

reload()

#### Example Implementation

component.reload();

// Component will enter the "LOADING" state. After all data is reloaded from 
// SFDC, component will enter the "VALID" state.

### removeCallback

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

#### API Version

55

#### Signature

removeCallback(event, callback)

#### Example Implementation

const onBeforeSaveCallback = () => console.log('onBeforeSave');

// Setup callback functions
component.setCallback('onBeforeSave', onBeforeSaveCallback);

// Remove the callback
component.removeCallback('onBeforeSave', onBeforeSaveCallback);

### 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.

#### API Version

55

#### Signature

save()

#### Example Implementation

// Create callback functions
const onBeforeSaveCallback = (data) => console.log('onBeforeSave', data.operation === 'save');
const onAfterSaveCallback = (data) => console.log('onAfterSave', data.operation === 'save');
const onAfterSyncCallback = () => console.log('onAfterSync');

// Setup callback functions
component.setCallback('onBeforeSave', onBeforeSaveCallback);
component.setCallback('onAfterSave', onAfterSaveCallback);
component.setCallback('onAfterSync', onAfterSyncCallback);

component.save();

// onBeforeSaveCallback is executed
// Data is saved to SFDC
// onAfterSaveCallback is executed
// Promotion is synchronized fo Processing Services
// onAfterSyncCallback is executed

### 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.

#### Example

![Note](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/images/icon_note.png)

#### Note

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

#### API Version

65

#### Signature

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.

#### Example Implementation

// Create callback functions
const onBeforeSaveCallback = (data) => console.log('onBeforeSave', data.operation === 'save');
const onAfterSaveCallback = (data) => console.log('onAfterSave', data.operation === 'save');
const onAfterSyncCallback = () => console.log('onAfterSync - Financial closure initiated');

// Setup callback functions
component.setCallback('onBeforeSave', onBeforeSaveCallback);
component.setCallback('onAfterSave', onAfterSaveCallback);
component.setCallback('onAfterSync', onAfterSyncCallback);

component.close();

// Phase is set to "ToBeFinanciallyClosed"
// onBeforeSaveCallback is executed
// Data is saved to Salesforce
// onAfterSaveCallback is executed
// Promotion is synchronized to Processing Services
// onAfterSyncCallback is executed
// Financial closure process begins in Processing Services

### selectTactic

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

#### API Version

55

#### Signature

selectTactic(tacticId)

#### Example Implementation

component.selectTactic('a37TC00000014j8YAA');

// After executing, the TPM UI will focus the tactic 'a37TC00000014j8YAA'

### setCallback

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

#### API Version

55

#### Signature

setCallback(tacticFunds)

#### Example Implementation

// Resolved promise

// Create callback functions
const onBeforeSaveCallback = (data) => {
    return new Promise((resolve, reject) => {
        window.setTimeout(() => {
            resolve();
        }, 2000);
    });
};
const onErrorCallback = (error) => console.log('onError', error);

// Setup callback functions
component.setCallback('onBeforeSave', onBeforeSaveCallback);
component.setCallback('onError', onErrorCallback);

component.save();

// onBeforeSaveCallback is executed
// Process wait the returned promise is resolved
// Data is saved to SFDC
// Save process continues

// Rejected promise

// Create callback functions
const onBeforeSaveCallback = (data) => {
    return new Promise((resolve, reject) => {
        window.setTimeout(() => {
            reject(new Error('My Error'));
        }, 2000);
    });
};
const onErrorCallback = (error) => console.log('onError', error);

// Setup callback functions
component.setCallback('onBeforeSave', onBeforeSaveCallback);
component.setCallback('onError', onErrorCallback);

component.save();

// onBeforeSaveCallback is executed
// Process wait the returned promise is resolved
// Promise is rejected
// onErrorCallback is executed with the rejected error

### 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..

#### API Version

55

#### Signature

setCustomState(customState)

#### Example Implementation

component.setCustomState(
    Object.assign({}, 
        oldCustomState, // Create a new object using the old one as baseline
        {
            myProp: 'Test'
        }
    )
);
   

### setEditMode

Sets the promotion into edit mode or exits edit mode.

#### API Version

55

#### Signature

setEditMode(value)

#### Example Implementation

component.setEditMode(true);

// After executing, the TPM UI will set the promotion into edit mode

component.setEditMode(false);

// After executing, the TPM UI will set the promotion into read only mode 

### setEditable

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.

#### API Version

60.0

#### Signature

setEditable(recordId, eaRight, value)

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

### setVisible

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.

#### API Version

60.0

#### Signature

setVisible(recordId, eaRight, value)

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

### setParticipatingCustomers

Lists the objects with the participating customers format.

#### API Version

55

#### Signature

setParticipatingCustomers(participatingCustomers)

#### Example Implementation

component.setParticipatingCustomers(\[ // Array of items
    {
        "included": true, // Is Included?
        "externalid": "Supermarkets" // External id of the Participating Customer
    }
\]);

### setPLGridFilterOpen

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

#### API Version

55

#### Signature

setPLGridFilterOpen(value)

#### Example Implementation

component.setPLGridFilterOpen(true);

// After executing, the TPM UI will open the PL Grid filters

component.setPLGridFilterOpen(false);

// After executing, the TPM UI will close the PL Grid filters 

### setPromotionAttachmentLinks

Sets the related promotion attachment links to the promotion.

#### API Version

55

#### Signature

setPromotionAttachmentLinks(attachmentLinks)

#### Example Implementation

component.setPromotionAttachmentLinks(\[ // An array of objects
    {
        IsNew: false, // Flag to indicate if the record is new
        IsDeleted: false, // Flag to indicate if the record is deleted
        Id : 'a40TC00000014j8YAA', // Record id of the Promotion Attachment Link record
        cgcloud\_\_Promotion\_Attachment\_\_c: 'a41TC00000014j8YAA', // Record attribute. 
            // Reference to the Promotion\_Attachment\_\_c record
        // All Tactic Fund record fields will be present as attributes
        ...
    },
    ...
\]);

### 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.

#### API Version

55

#### Signature

setPromotionAttachments(attachments)

#### Example Implementation

component.setPromotionAttachments(\[ // An array of objects
    {
        IsNew: false, // Flag to indicate if the record is new. Promotion attachments cannot be flagged as new
        IsDeleted: false, // Flag to indicate if the record is deleted. Promotion attachments cannot be flagged as deleted
        Id : 'a41TC00000014j8YAA', // Record id of Promotion Attachment record
        cgcloud\_\_Description\_Language\_1\_\_c: 'Sample Attachment', // Record attribute. Reference to the Promotion\_Attachment\_\_c record
        // All Tactic Fund record fields will be present as attributes
        ...
    },
    ...
\]);

### setPromotionCategories

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

#### API Version

55

#### Signature

setPromotionCategories(categories)

#### Example Implementation

component.setPromotionCategories(\[ // Array
    '01t17000001siy5AAA' // Product2 Id referencing a Category record
\]);

### setPromotionField

Sets a promotion SObject field.

#### API Version

55

#### Signaturei

setPromotionField(field, value)

#### Example Implementation

component.setPromotionField(
    'cgcloud\_\_Slogan\_Language\_1\_\_c', // Field name
    'Test Slogan' // value
);

![Note](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/images/icon_note.png)

#### Note

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.

### setPromotionManualInputs

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.

#### API Version

60.0

#### Signature

setPromotionManualInputs(manualInputs)

#### Example Implementation

// Import the TPMManualInput class to create new instances
import { TPMManualInput } from 'cgcloud/tpmGenericUtils';

...
   
// In this method, we will be adding a new manual input to the grid.
// This can, for instance, be executed in the click of a button or after
// some user interaction
async addNewManualInputs() {
    const tpmPromotion = this.template.querySelector('cgcloud-tpm-promotion');
        
    // Extract the current manual inputs
    const currentManualInputs = tpmPromotion.getProperty('manualInputs');
        
    // You can read information from the current manual inputs:
    currentManualInputs.forEach((mi) => {
        console.log(mi.getKPICode()); // 'ABCD'
        console.log(mi.getPeriodDateFrom()); // Date
        console.log(mi.getPeriodDateThru()); // Date
        console.log(mi.ProductId()); // '01tXXXXXXXXXXXXXXX'
        console.log(mi.getValue()); // 123
    });
        
    // Example: KPI code to set the manual input to
    const kpiCode = 'ABCD';

    // Example: Product Id to set the manual input to. If null,
    // the manual input will be applied to the "Total" for the KPI
    // productId can be any level on the product hierarchy that is part of 
    // the calculation (SubCategory, Brand, etc)
    const productId = '01tXXXXXXXXXXXXXXX';
        
    // Methods used to extract data from the grid require the grid to be in valid
    // status. If you try to extract data from the grid when not in the correct status,
    // an exception will be thrown
    if (tpmPromotion.getProperty('calculationStatus') !== 'VALID') {
        throw new Error('Grid not in VALID status');
    }
        
    // Extract the periods information from the grid
    const periods = await tpmPromotion.getPeriods();
        
    // We find the period where we want to set the manual input.
    // You can find periods by name or use the periods "dateFrom, "dateThru" and "periodtype"
    // attributes to search for an specific period.
    // In this example, we will set the manual input on the "Total" period
    // that uses a specific label
    const manualInputPeriod = periods.find((p) => p.periodtype === 'Total');
        
    // Create a new instance
    const newManualInput = new TPMManualInput({
        kpiCode: kpiCode,
        period: manualInputPeriod,
        productId: productId,
        value: 123 // Value to set
    });
        
    // Create a new array with our new manual input appended
    const newManualInputArray = \[...currentManualInputs, newManualInput\];
        
    // Set the manual inputs
    tpmPromotion.setPromotionManualInputs(newManualInputArray);
        
    // After setting the new manual inputs, the grids will be automatically
    // reloaded and re-rendered with the new values in place.
    
    // At this point, manual inputs are still not saved to SFDC database.
    // the user must save the promotion
}

### setSubAccounts

Lists the objects with the SubAccounts format.

#### API Version

55

#### Signature

setSubAccounts(subAccounts)

#### Example Implementation

component.setParticipatingCustomers(\[ // Array of items
    {
        "volume": 50, // Percent of volume for this sub account. 
                // Sum of included sub accounts volume must be 100 or less
        "included": true, // Is Included?
        "externalid": "Supermarkets" // External id of the SubAccount
    }
\]);

### setTacticConditionCreationDefinitions

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

#### API Version

55

#### Signature

setTacticConditionCreationDefinitions(tacticConditionCreationDefinitions)

#### Example Implementation

component.setTacticConditionCreationDefinitions(\[ // An array of objects
    {
        IsNew: false, // Flag to indicate if the record is new
        IsDeleted: false, // Flag to indicate if the record is deleted
        Id : 'a50TC00000014j8YAA', // Record id
        cgcloud\_\_Tactic\_\_c: 'a37TC00000014j8YAA', // Record attribute. 
        // All Tactic condition creation definition record fields will be present as attributes
        ...
    },
    ...
\]);

### setTacticField

Sets the tactic SObject field.

#### API Version

55

#### Signature

setTacticField(tacticId, field, value)

#### Example Implementation

component.setTacticField(
    'a37TC00000014j8YAA', // Tactic field to set
    'cgcloud\_\_Comment\_\_c', // Field name
    'Sample Tactic' // value
);

![Note](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/images/icon_note.png)

#### Note

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.

### 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.

#### API Version

55

#### Signature

setTacticFunds(tacticFunds)

#### Example Implementation

component.setTacticFunds(
    \[ // An array of objects
        {
            IsNew: false, // Flag to indicate if the record is new
            IsDeleted: false, // Flag to indicate if the record is deleted
            Id : 'a38TC00000014j8YAA', // Record id
            cgcloud\_\_Fund\_\_c: 'a39TC00000014j8YAA', // Record attribute. Reference to the Fund\_\_c record
            cgcloud\_\_Tactic\_\_c: 'a37TC00000014j8YAA', // Record attribute. Reference to the Tactic\_\_c record
            // All Tactic Fund record fields will be present as attributes
            ...
        },
        ...
\]);

![Note](https://developer.salesforce.com/docs/atlas.en-us.retail_api.meta/retail_api/images/icon_note.png)

#### Note

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.

### 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.

#### API Version

58.0

#### Signature

predictUplift()

#### Example Implementation

const api = this.template.querySelector('cgcloud-tpm-promotion');


api.predictUplift()
    .then(() => {
        // Uplift Prediction success
    })
    .catch((error) => {
        console.log(error.message); // error message
    });