Newer Version Available

This content describes an older version of this product. View Latest

tpm-promotion Component Reference

This lightning web component is a service component that loads a TPM Promotion exposing methods to update the Promotion state and emitting events to keep all UI components in the promotion page in sync when the promotion state changes. This component is a lightning web component that will be provided as part of the released managed package.

The content in this Consumer Goods Cloud Trade Promotion Management documentation is confidential and may be viewed only by customers or partners as authorized by Salesforce, and copying and further distribution is prohibited without prior written consent from Salesforce. The content is the highly confidential and proprietary information of Salesforce and is protected under the confidentiality obligations of your Agreement with Salesforce. Accordingly, the content may be used only as necessary in order to implement the Consumer Goods Cloud Trade Promotion Management functionality.

The content in this documentation is being released as a preview, and is not generally available and may contain errors. Salesforce is providing this documentation as-is, and makes no representations or warranties as to the accuracy of the content contained in this documentation. Salesforce reserves the right to update and revise this documentation, and content describing features of Consumer Goods Cloud Trade Promotion Management may be modified, added, or removed. If Salesforce distributes or releases updated versions of this documentation, you acknowledge and agree that you will delete and destroy any prior versions of this documentation.

Important

Namespace

1cgcloud

Events

1{
2    detail : {
3        value: <<new value>>,
4        property: <<the property>>,
5        promotionId: <<promotionId>>,
6    }
7}

onfocusedareachange

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

1{
2    detail : {
3        value: {
4            area: 'PROMOTION_PLANNING',
5            section: 'PROMOTION'
6        },
7        property: 'focusedArea',
8        promotionId: 'a2WTC0000000F772AE',
9    }
10}

onisplgridfilteropenchange

This event is triggered every time the P&L Filters are opened (true) or closed (false).

1{
2    detail : {
3        value: true,
4        property: 'isPLGridFilterOpen',
5        promotionId: 'a2WTC0000000F772AE',
6    }
7}

onstatuschange

This event is triggered every time the tpm promotion component lifecycle state changes. Status changes are triggered by lifecycle operations on the Promotion record.

1{
2    detail : {
3        value: 'VALID',
4        property: 'status',
5        promotionId: 'a2WTC0000000F772AE',
6    }
7}

oncalculationstatuschange

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

1{
2    detail : {
3        value: 'LOADING',
4        property: 'calculationStatus',
5        promotionId: 'a2WTC0000000F772AE',
6    }
7}

oneditmodechange

This event is triggered every time the edit mode changes for the page.

1{
2    detail : {
3        value: true,
4        property: 'editMode',
5        promotionId: 'a2WTC0000000F772AE',
6    }
7}

onselectedtacticidchange

This event is triggered every time the focused tactic changes.

1{
2    detail : {
3        value: 'a37TC00000014j8YAA',
4        property: 'tacticId',
5        promotionId: 'a2WTC0000000F772AE',
6    }
7}

onpromotionchange

This event is triggered every time any the promotion attributes change.

1{
2    detail : {
3        value: {
4            IsNew: false, // Flag to indicate if the record is new
5            IsDeleted: false, // Flag to indicate if the record is deleted
6            Id : 'a2WTC0000000F772AE', // Record id
7            cgcloud__Slogan__c: 'Sample Promotion', // Record attribute. 
8            // All Promotion record fields will be present as attributes
9            ...
10        },
11        property: 'promotion',
12        promotionId: 'a2WTC0000000F772AE',
13    }
14}

oneffectivecategorieschange

This event is triggered every time the promotion effective categories change.

1{
2    detail : {
3        value: [ // Array of Category product ids
4            "01t17000001siy5AAA"
5        ],
6        property: 'effectiveCategories',
7        promotionId: 'a2WTC0000000F772AE',
8    }
9}

oneffectivebrandschange

This event is triggered every time the promotion effective brands change.

1{
2    detail : {
3        value: [ // Array of Brand product ids
4            "01t17000001siy5AAA"
5        ],
6        property: 'effectiveBrands',
7        promotionId: 'a2WTC0000000F772AE',
8    }
9}

ontacticschange

This event is triggered any time any of the Tactic attributes change.

1{
2    detail : {
3        value: [ // An array of objects
4            {
5                IsNew: false, // Flag to indicate if the record is new
6                IsDeleted: false, // Flag to indicate if the record is deleted
7                Id : 'a37TC00000014j8YAA', // Record id
8                cgcloud__Comment__c: 'Sample Tactic', // Record attribute. 
9                // All Tactic record fields will be present as attributes
10                ...
11                // Additional Fields
12                ProductFilter: {...}, // contains the Tactic Product Filter
13                EffectiveCategories: [...] // List of Effective categories for the tactic
14                EffectiveBrands: [...] // List of Effective brands for the tactic
15            },
16            ...
17        ],
18        property: 'tactics',
19        promotionId: 'a2WTC0000000F772AE',
20    }
21}

ontacticfundschange

This event is triggered any time any of the Tactic Fund properties change.

1{
2    detail : {
3        value: [ // An array of objects
4            {
5                IsNew: false, // Flag to indicate if the record is new
6                IsDeleted: false, // Flag to indicate if the record is deleted
7                Id : 'a38TC00000014j8YAA', // Record id
8                cgcloud__Fund__c: 'a39TC00000014j8YAA', // Record attribute. Reference to the Fund__c record
9                cgcloud__Tactic__c: 'a37TC00000014j8YAA', // Record attribute. Reference to the Tactic__c record
10                // All Tactic Fund record fields will be present as attributes
11                ...
12            },
13            ...
14        ],
15        property: 'tacticFunds',
16        promotionId: 'a2WTC0000000F772AE',
17    }
18}

onpromotionattachmentlinkschange

This event is triggered any time any of the Promotion Attachment Link properties change.

1{
2    detail : {
3        value: [ // An array of objects
4            {
5                IsNew: false, // Flag to indicate if the record is new
6                IsDeleted: false, // Flag to indicate if the record is deleted
7                Id : 'a40TC00000014j8YAA', // Record id
8                cgcloud__Promotion_Attachment__c: 'a41TC00000014j8YAA', // Record attribute. Reference to the Promotion_Attachment__c record
9                // All Tactic Fund record fields will be present as attributes
10                ...
11            },
12            ...
13        ],
14        property: 'promotionAttachmentLinks',
15        promotionId: 'a2WTC0000000F772AE',
16    }
17}

onpromotionattachmentschange

This event is triggered any time any of the Promotion Attachment properties change.

1{
2    detail : {
3        value: [ // An array of objects
4            {
5                IsNew: false, // Flag to indicate if the record is new. Promotion attachments cannot be flagged as new
6                IsDeleted: false, // Flag to indicate if the record is deleted. Promotion attachments cannot be flagged as deleted
7                Id : 'a41TC00000014j8YAA', // Record id
8                cgcloud__Description_Language_1__c: 'Sample Attachment', // Record attribute. Reference to the Promotion_Attachment__c record
9                // All Tactic Fund record fields will be present as attributes
10                ...
11            },
12            ...
13        ],
14        property: 'promotionAttachments',
15        promotionId: 'a2WTC0000000F772AE',
16    }
17}

onpromotioncategorieschange

This event is triggered any time the promotion categories change.

1{
2    detail : {
3        value: [ "01t17000001siy5AAA" ],
4        property: 'promotionCategories',
5        promotionId: 'a2WTC0000000F772AE',
6    }
7}

onparticipatingcustomerschange

This event is triggered any time the promotion participating customers change. The participating customers list is used on determining the customers the Promotion will be pushed during the push process.

1{
2    detail : {
3        value: [ // Array of items
4            {
5                "included": true, // Is Included?
6                "externalid": "Supermarkets" // External id of the Participating Customer
7            }
8        ],
9        property: 'participatingCustomers',
10        promotionId: 'a2WTC0000000F772AE',
11    }
12}

ontacticconditioncreationdefinitionschange

This event is triggers any time the Tactic Condition Creation Definitions for the tactics included in the Promotion change Value is an array with Tactic Condition Creation Definition SObject records:

1{
2    detail : {
3        value: [ // An array of objects
4            {
5                IsNew: false, // Flag to indicate if the record is new
6                IsDeleted: false, // Flag to indicate if the record is deleted
7                Id : 'a50TC00000014j8YAA', // Record id
8                cgcloud__Tactic__c: 'a37TC00000014j8YAA', // Record attribute. 
9                // All Tactic condition creation definition record fields will be present as attributes
10                ...
11            },
12            ...
13        ],
14        property: 'tacticConditionCreationDefinitions',
15        promotionId: 'a2WTC0000000F772AE',
16    }
17}

oncustomstatechange

This event is triggered every time the custom state changes. Custom State is a special area of the promotion state where customers can set their custom structures that will be sent to Salesforce to be processed and committed at the same time as the promotion.

1{
2    detail : {
3        value: {...} // Custom object
4        property: 'customState',
5        promotionId: 'a2WTC0000000F772AE',
6    }
7}

tpm-promotion Component Reference Methods

The following are methods for tpm-promotion Component Reference.

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

1component.generateTactic('a43TC00000014j8YAA') // tactic Id as parameter
2    .then((tactic) => {
3        // Add the tactic to the Promotion component
4        Object.keys(tactic).forEach((key) => {
5            component.setTacticField(tactic.Id, key, tactic[key]);
6        });
7    });

navigateTo

Imperatively retrieve promotion state properties.

API Version

55

Signature

getProperty(target)

Example Implementation

1component.getProperty('promotion');
2
3// Returns a Javascript object with attributes mapped to all promotion SObject
4// attributes
5// {
6//     IsNew: false, // Flag to indicate if the record is new
7//     IsDeleted: false, // Flag to indicate if the record is deleted
8//     Id : 'a2WTC0000000F772AE', // Record id
9//     cgcloud__Slogan__c: 'Sample Promotion', // Record attribute. 
10//     // All Promotion record fields will be present as attributes
11//     ...
12// }

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

1// Create callback functions
2const onBeforeSaveCallback = (data) => console.log('onBeforeSave', data.operation === 'push');
3const onAfterSaveCallback = (data) => console.log('onAfterSave', data.operation === 'push');
4const onAfterPushCallback = () => console.log('onAfterPush');
5const onErrorCallback = (error) => console.log('onError', error);
6
7// Setup callback functions
8component.setCallback('onBeforeSave', onBeforeSaveCallback);
9component.setCallback('onAfterSave', onAfterSaveCallback);
10component.setCallback('onAfterPush', onAfterPushCallback);
11component.setCallback('onError', onErrorCallback);
12
13component.push();
14
15// If the promotion is not pushable, onErrorCallback will be executed with an error message
16
17// onBeforeSaveCallback is executed
18// Data is saved to SFDC
19// onAfterSaveCallback is executed
20// Promotion Push process is scheduled
21// onAfterPushCallback is executed

reload

Reloads the promotion SObject and all the related records.

API Version

55

Signature

reload()

Example Implementation

1component.reload();
2
3// Component will enter the "LOADING" state. After all data is reloaded from 
4// 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

1const onBeforeSaveCallback = () => console.log('onBeforeSave');
2
3// Setup callback functions
4component.setCallback('onBeforeSave', onBeforeSaveCallback);
5
6// Remove the callback
7component.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

1// Create callback functions
2const onBeforeSaveCallback = (data) => console.log('onBeforeSave', data.operation === 'save');
3const onAfterSaveCallback = (data) => console.log('onAfterSave', data.operation === 'save');
4const onAfterSyncCallback = () => console.log('onAfterSync');
5
6// Setup callback functions
7component.setCallback('onBeforeSave', onBeforeSaveCallback);
8component.setCallback('onAfterSave', onAfterSaveCallback);
9component.setCallback('onAfterSync', onAfterSyncCallback);
10
11component.save();
12
13// onBeforeSaveCallback is executed
14// Data is saved to SFDC
15// onAfterSaveCallback is executed
16// Promotion is synchronized fo Processing Services
17// onAfterSyncCallback is executed

selectTactic

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

API Version

55

Signature

selectTactic(tacticId)

Example Implementation

1component.selectTactic('a37TC00000014j8YAA');
2
3// 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

1// Resolved promise
2
3// Create callback functions
4const onBeforeSaveCallback = (data) => {
5    return new Promise((resolve, reject) => {
6        window.setTimeout(() => {
7            resolve();
8        }, 2000);
9    });
10};
11const onErrorCallback = (error) => console.log('onError', error);
12
13// Setup callback functions
14component.setCallback('onBeforeSave', onBeforeSaveCallback);
15component.setCallback('onError', onErrorCallback);
16
17component.save();
18
19// onBeforeSaveCallback is executed
20// Process wait the returned promise is resolved
21// Data is saved to SFDC
22// Save process continues
23
24// Rejected promise
25
26// Create callback functions
27const onBeforeSaveCallback = (data) => {
28    return new Promise((resolve, reject) => {
29        window.setTimeout(() => {
30            reject(new Error('My Error'));
31        }, 2000);
32    });
33};
34const onErrorCallback = (error) => console.log('onError', error);
35
36// Setup callback functions
37component.setCallback('onBeforeSave', onBeforeSaveCallback);
38component.setCallback('onError', onErrorCallback);
39
40component.save();
41
42// onBeforeSaveCallback is executed
43// Process wait the returned promise is resolved
44// Promise is rejected
45// 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

1component.setCustomState(
2    Object.assign({}, 
3        oldCustomState, // Create a new object using the old one as baseline
4        {
5            myProp: 'Test'
6        }
7    )
8);

setEditMode

Sets the promotion into edit mode or exits edit mode.

API Version

55

Signature

setEditMode(value)

Example Implementation

1component.setEditMode(true);
2
3// After executing, the TPM UI will set the promotion into edit mode
4
5component.setEditMode(false);
6
7// After executing, the TPM UI will set the promotion into read only mode

setParticipatingCustomers

Lists the objects with the participating customers format.

API Version

55

Signature

setParticipatingCustomers(participatingCustomers)

Example Implementation

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

setPLGridFilterOpen

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

API Version

55

Signature

setPLGridFilterOpen(value)

Example Implementation

1component.setPLGridFilterOpen(true);
2
3// After executing, the TPM UI will open the PL Grid filters
4
5component.setPLGridFilterOpen(false);
6
7// After executing, the TPM UI will close the PL Grid filters

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

1component.setPromotionAttachments([ // An array of objects
2    {
3        IsNew: false, // Flag to indicate if the record is new. Promotion attachments cannot be flagged as new
4        IsDeleted: false, // Flag to indicate if the record is deleted. Promotion attachments cannot be flagged as deleted
5        Id : 'a41TC00000014j8YAA', // Record id of Promotion Attachment record
6        cgcloud__Description_Language_1__c: 'Sample Attachment', // Record attribute. Reference to the Promotion_Attachment__c record
7        // All Tactic Fund record fields will be present as attributes
8        ...
9    },
10    ...
11]);

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

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

setPromotionField

Sets a promotion SObject field.

API Version

55

Signature

setPromotionField(field, value)

Example Implementation

1component.setPromotionField(
2    'cgcloud__Slogan_Language_1__c', // Field name
3    'Test Slogan' // value
4);

setSubAccounts

Lists the objects with the SubAccounts format.

API Version

55

Signature

setSubAccounts(subAccounts)

Example Implementation

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

setTacticConditionCreationDefinitions

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

API Version

55

Signature

setTacticConditionCreationDefinitions(tacticConditionCreationDefinitions)

Example Implementation

1component.setTacticConditionCreationDefinitions([ // An array of objects
2    {
3        IsNew: false, // Flag to indicate if the record is new
4        IsDeleted: false, // Flag to indicate if the record is deleted
5        Id : 'a50TC00000014j8YAA', // Record id
6        cgcloud__Tactic__c: 'a37TC00000014j8YAA', // Record attribute. 
7        // All Tactic condition creation definition record fields will be present as attributes
8        ...
9    },
10    ...
11]);

setTacticField

Sets the tactic SObject field.

API Version

55

Signature

setTacticField(tacticId, field, value)

Example Implementation

1component.setTacticField(
2    'a37TC00000014j8YAA', // Tactic field to set
3    'cgcloud__Comment__c', // Field name
4    'Sample Tactic' // value
5);

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

1component.setTacticFunds(
2    [ // An array of objects
3        {
4            IsNew: false, // Flag to indicate if the record is new
5            IsDeleted: false, // Flag to indicate if the record is deleted
6            Id : 'a38TC00000014j8YAA', // Record id
7            cgcloud__Fund__c: 'a39TC00000014j8YAA', // Record attribute. Reference to the Fund__c record
8            cgcloud__Tactic__c: 'a37TC00000014j8YAA', // Record attribute. Reference to the Tactic__c record
9            // All Tactic Fund record fields will be present as attributes
10            ...
11        },
12        ...
13]);