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
1cgcloud
Events
Here’s the event payload structure.
1{2 detail : {3 value: <<new value of the property>>,4 property: <<property name>>,5 recordId: <<promotionId>>6 }7}
onfocusedareachange
This event is triggered when a different area of the application is navigated to.
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.
This event is triggered when the promotion attributes change.
The event value contains all the Promotion SObject attributes.
1{2 detail : {3 value: {4 IsNew: false, // Flag to indicate if the record is new5 IsDeleted: false, // Flag to indicate if the record is deleted6 Id : 'a2WTC0000000F772AE', // Record id7 cgcloud__Slogan__c: 'Sample Promotion' // Record attribute. 8 // All Promotion record fields will be present as attributes9 },10 property: 'promotion',11 promotionId: 'a2WTC0000000F772AE'12 }13}
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.
This event is triggered when the tactic attributes change.
The event value contains all the Tactic sObjects and their attributes.
1{2 detail : {3 value: [ // An array of objects4 {5 IsNew: false, // Flag to indicate if the record is new6 IsDeleted: false, // Flag to indicate if the record is deleted7 Id : 'a37TC00000014j8YAA', // Record ID8 cgcloud__Comment__c: 'Sample Tactic', // Record attribute. 9 // All tactic record fields will be present as attributes10 ...11 // Additional Fields12 ProductFilter: {...}, // contains the Tactic Product Filter13 EffectiveCategories: [...], // List of effective categories for the tactic14 EffectiveBrands: [...] // List of effective brands for the tactic 15 },16 ...17 ],18 property: 'tactics',19 promotionId: 'a2WTC0000000F772AE'20 }21}
ontacticfundschange
This event is triggered when the Tactic fund properties change.
The event value contains all the Tactic Fund sObjects and their attributes.
1{2 detail : {3 value: [ // An array of objects4 {5 IsNew: false, // Flag to indicate if the record is new6 IsDeleted: false, // Flag to indicate if the record is deleted7 Id : 'a38TC00000014j8YAA', // Record ID8 cgcloud__Fund__c: 'a39TC00000014j8YAA', // Record attribute. Reference to the Fund__c record9 cgcloud__Tactic__c: 'a37TC00000014j8YAA', // Record attribute. Reference to the Tactic__c record10 // All Tactic Fund record fields will be present as attributes11 ...12 },13 ...14 ],15 property: 'tacticFunds',16 promotionId: 'a2WTC0000000F772AE'17 }18}
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.
1{2 detail : {3 value: [ // An array of objects4 {5 IsNew: false, // Flag to indicate if the record is new6 IsDeleted: false, // Flag to indicate if the record is deleted7 Id : 'a40TC00000014j8YAA', // Record ID8 cgcloud__Promotion_Attachment__c: 'a41TC00000014j8YAA', // Record attribute. Reference to the Promotion_Attachment__c record9 // All Tactic Fund record fields will be present as attributes10 ...11 },12 ...13 ],14 property: 'promotionAttachmentLinks',15 promotionId: 'a2WTC0000000F772AE'16 }17}
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.
1{2 detail : {3 value: [ // An array of objects4 {5 IsNew: false, // Flag to indicate if the record is new. Promotion attachments cannot be flagged as new6 IsDeleted: false, // Flag to indicate if the record is deleted. Promotion attachments cannot be flagged as deleted7 Id : 'a41TC00000014j8YAA', // Record ID8 cgcloud__Description_Language_1__c: 'Sample Attachment', // Record attribute. Reference to the Promotion_Attachment__c record9 // All Tactic Fund record fields will be present as attributes10 ...11 },12 ...13 ],14 property: 'promotionAttachments',15 promotionId: 'a2WTC0000000F772AE'16 }17}
onpromotioncategorieschange
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.
1{2 detail : {3 value: [ // Array of items4 {5 "volume": 50, // Percent of volume for this sub account. Sum of included sub accounts volume must be 100 or less6 "included": true, // Is Included?7 "externalid": "Supermarkets" // External id of the SubAccount8 }9 ],10 property: 'subAccounts',11 recordId: 'a2WTC0000000F772AE'12 }13}
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.
1{2 detail : {3 value: [ // Array of items4 {5 "included": true, // Is Included?6 "externalid": "Supermarkets" // External id of the Participating Customer7 }8 ],9 property: 'participatingCustomers',10 promotionId: 'a2WTC0000000F772AE'11 }12}
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.
1{2 detail : {3 value: [ // An array of objects4 {5 IsNew: false, // Flag to indicate if the record is new6 IsDeleted: false, // Flag to indicate if the record is deleted7 Id : 'a50TC00000014j8YAA', // Record id8 cgcloud__Tactic__c: 'a37TC00000014j8YAA', // Record attribute. 9 // All Tactic condition creation definition record fields will be present as attributes10 ...11 },12 ...13 ],14 property: 'tacticConditionCreationDefinitions',15 promotionId: 'a2WTC0000000F772AE'16 }17}
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.
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 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.
1{2 detail : {3 value: {4 errorAmount: 1, // Total number of errors5 errorMessages: [ // Sample of messages6 {7 productid: '01tXXXXXXXXXXXXXXX', // Product8 productgroupid: '01tYYYYYYYYYYYYYYY', // Product Group9 kpiname: 'TEST', // Name of the KPI10 values: [11 1,12 213 ],14 tacticid: 'aaa000000000000000', // Tactic Id15 weeklabel: '03/2023' // Period label16 }17 ]18 },19 property: 'calculationStatus',20 recordId: 'a2WTC0000000F772AE'21 }22}
Example Implementation
Here’s an example of how to use the tpm-promotion component to interact with a promotion:
1// myComponent.html2<template>3 <!-- Instantiate a tpm-promotion component to bridge -->4 <!-- with the Promotion state -->5 <cgcloud-tpm-promotion 6 promotion-id={recordId}7 onpromotionchange={onPromotionChange}8 oneditmodechange={onEditModeChange}>9 </cgcloud-tpm-promotion>1011 <!-- Create a card component with a Form item to allow a field -->12 <!-- to be editable, this field will be aligned to page edit mode -->13 <lightning-card title="My Card">14 <lightning-record-form15 object-api-name="cgcloud__Promotion__c"16 record-type-id={myRecordTypeId} <!-- Used to load field specific metadata -->17 >18 <lightning-input-field 19 field-name="MyPromotionField__c"20 disabled={notInEditMode}21 value={myPromotionFieldValue}22 onchange={onFieldValueChange}23 ></lightning-input-field>24 </lightning-record-form>25 </lightning-card>26</template>
1import { LightningElement, api } from 'lwc';23export default class SampleTpmPromotionDetails extends LightningElement {4 // Required to get the promotion id of the page5 @api recordId;67 notInEditMode = false;8 myPromotionFieldValue = '';9 myRecordTypeId = '';1011 // Executed every time the editMode changes for the promotion12 // Field will be editable if in Edit mode13 onEditModeChange(event) {14 this.notInEditMode = !event.detail.value;15 }1617 // Executed every time the promotion value changes 18 onPromotionChange(event) {19 this.myPromotionFieldValue = event.detail.value['MyPromotionField__c'];20 this.myRecordTypeId = event.detail.value['RecordTypeId'];21 }2223 // Executed when the editable field changes24 onFieldValueChange(event) {25 // Get the tpm-promotion component26 const component = this.template.querySelector('cgcloud-tpm-promotion');2728 // Update the promotion state with the new field value29 component.setPromotionField(30 'MyPromotionField__c',31 event.detail.value32 ); 33}
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.
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.
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.
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 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 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.
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
Name
Type
Description
Required or Optional
options.subsets
List<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.kpis
List<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.levels
List<String>
List of loaded levels to retrieve data from. You can get a list of loaded levels using the getLevelNames() method.
Optional
options.periods
List<String>
List of loaded period types to retrieve data. You can get a list of loaded period types using the getPeriodTypes() method.
Optional
options.format
List<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.
Example Implementation
1const api = this.template.querySelector('cgcloud-tpm-promotion');23// Export options, the possible values can be extracted using4// the other described methods5const exportOptions = {6 subsets: ["Planning"], // Subsets to request data7 periods: [8 "Total",9 "Week"10 ],11 levels: [12 "Total",13 "Category",14 "Product"15 ],16 format: "json"17};1819// Correct Scenario20api.getProperty('calculationStatus'); // 'VALID'2122api.exportKPIs(exportOptions)23 .then((data) => {24 // Example response as CSV25 //26 // kpiName,Category,Product,AP_LBL_TOTAL,03/2022,04/202227 // SampleKPI1,,,246,123,12328 // SampleKPI1,01tTC0000000001AAA,,246,123,12329 // SampleKPI1,01tTC0000000001AAA,01tTC0000000002AAA,246,123,12330 // SampleKPI2,,,1974,987,98731 // SampleKPI2,01tTC0000000001AAA,,1974,987,98732 // SampleKPI2,01tTC0000000001AAA,01tTC0000000002AAA,1974,987,9873334 // Example response as JSON35 //36 // [{37 // kpiName: "SampleKPI1",38 // Category: null,39 // Product: null,40 // AP_LBL_TOTAL: 246,41 // "03/2022": 123,42 // "04/2022": 123 43 // }, {44 // kpiName: "SampleKPI1",45 // Category: "01tTC0000000001AAA",46 // Product: null,47 // AP_LBL_TOTAL: 246,48 // "03/2022": 123,49 // "04/2022": 12350 // },{51 // kpiName: "SampleKPI1",52 // Category: "01tTC0000000001AAA",53 // Product: "01tTC0000000002AAA",54 // AP_LBL_TOTAL: 246,55 // "03/2022": 123,56 // "04/2022": 12357 // },{58 // kpiName: "SampleKPI2",59 // Category: null,60 // Product: null,61 // AP_LBL_TOTAL: 1974,62 // "03/2022": 987,63 // "04/2022": 98764 // },{65 // kpiName: "SampleKPI2",66 // Category: "01tTC0000000001AAA",67 // Product: null,68 // AP_LBL_TOTAL: 1974,69 // "03/2022": 987,70 // "04/2022": 98771 // },{72 // kpiName: "SampleKPI2",73 // Category: "01tTC0000000001AAA",74 // Product: "01tTC0000000002AAA",75 // AP_LBL_TOTAL: 1974,76 // "03/2022": 987,77 // "04/2022": 98778 // }]798081 // We can access the properties on the result:82 const firstRecord = data[0];8384 console.log(firstRecord["kpiName"]); // "SampleKPI1"85 // Since we request the total period, 86 // we can read the total period value87 console.log(firstRecord["AP_LBL_TOTAL"]); // 24688 // We can also read specific periods information89 console.log(firstRecord["03/2022"]); // 12390 // We can also know which level the row references 91 console.log(firstRecord["Category"]); // null92 console.log(firstRecord["Product"]); // null93 // Since Category is null, it means this data row 94 // represents the total value for KPI "SampleKPI1" 9596 // For last record97 const lastRecord = data[data.length - 1];9899 console.log(lastRecord["kpiName"]); // "SampleKPI2"100 // Since we request the total period, 101 // we can read the total period value102 console.log(lastRecord["AP_LBL_TOTAL"]); // 1974103 // We can also read specific periods information104 console.log(lastRecord["03/2022"]); // 987105 // We can also know which level the row references 106 console.log(lastRecord["Category"]); // "01tTC0000000001AAA"107 console.log(lastRecord["Product"]); // "01tTC0000000002AAA"108 // Since Product is not null, it means this data row 109 // represents the value for KPI "SampleKPI2" for that110 // specific product111 });112113// Error Scenario114api.getProperty('calculationStatus'); // 'LOADING'115116api.exportKPIs(exportOptions)117 .catch((error) => {118 console.log(error.message); // CalculationStatus is not "VALID". Current Status "LOADING"119 });
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
1component.duplicateTactic('a43TC00000014j8YAA') // tactic ID as a parameter2 .then((tactic) => {3 // Add the tactic to the promotion component4 Object.keys(tactic).forEach((key) => {5 component.setTacticField(tactic.Id, key, tactic[key]);6 });7 });
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 parameter2 .then((tactic) => {3 // Add the tactic to the Promotion component4 Object.keys(tactic).forEach((key) => {5 component.setTacticField(tactic.Id, key, tactic[key]);6 });7 });
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
1component.getProperty('promotion');23// Returns a Javascript object with attributes mapped to all promotion SObject4// attributes5// {6// IsNew: false, // Flag to indicate if the record is new7// IsDeleted: false, // Flag to indicate if the record is deleted8// Id : 'a2WTC0000000F772AE', // Record id9// cgcloud__Slogan__c: 'Sample Promotion', // Record attribute. 10// // All Promotion record fields will be present as attributes11// ...12// }
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.
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.
API Version
58.0
Signature
getPeriods()
Example Implementation
1const api = this.template.querySelector('cgcloud-tpm-promotion');23// Correct Scenario4api.getProperty('calculationStatus'); // 'VALID'56api.getPeriods()7 .then((periods) => {8 // 0 9 console.log(periods[0].id); // "0"10 console.log(periods[0].name); // "AP_LBL_TOTAL" (label of the period)11 console.log(periods[0].periodtype); // "Total"12 console.log(periods[0].dateFrom); // null13 console.log(periods[0].dateThru); // null14 // 1 15 console.log(periods[1].id); // 116 console.log(periods[1].name); // "36/2022" // label in case of label is specified alternativly it returns the ....17 console.log(periods[1].periodtype); // "Week"18 console.log(periods[1].dateFrom); // 1661731200000 timestamp19 console.log(periods[1].dateThru); // 1662249600000 timestamp20 });
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.
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
1component.navigateTo({2 area: 'PROMOTION_PLANNING',3 section: 'PROMOTION'4});56// 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
1// Create callback functions2const 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);67// Setup callback functions8component.setCallback('onBeforeSave', onBeforeSaveCallback);9component.setCallback('onAfterSave', onAfterSaveCallback);10component.setCallback('onAfterPush', onAfterPushCallback);11component.setCallback('onError', onErrorCallback);1213component.push();1415// If the promotion is not pushable, onErrorCallback will be executed with an error message1617// onBeforeSaveCallback is executed18// Data is saved to SFDC19// onAfterSaveCallback is executed20// Promotion Push process is scheduled21// onAfterPushCallback is executed
reload
Reloads the promotion SObject and all the related records.
API Version
55
Signature
reload()
Example Implementation
1component.reload();23// 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.
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 functions2const onBeforeSaveCallback = (data) => console.log('onBeforeSave', data.operation === 'save');3const onAfterSaveCallback = (data) => console.log('onAfterSave', data.operation === 'save');4const onAfterSyncCallback = () => console.log('onAfterSync');56// Setup callback functions7component.setCallback('onBeforeSave', onBeforeSaveCallback);8component.setCallback('onAfterSave', onAfterSaveCallback);9component.setCallback('onAfterSync', onAfterSyncCallback);1011component.save();1213// onBeforeSaveCallback is executed14// Data is saved to SFDC15// onAfterSaveCallback is executed16// Promotion is synchronized fo Processing Services17// 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
Promotion Closure should be enabled in the Promotion Template before using this method.
Note
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
1// Create callback functions2const onBeforeSaveCallback = (data) => console.log('onBeforeSave', data.operation === 'save');3const onAfterSaveCallback = (data) => console.log('onAfterSave', data.operation === 'save');4const onAfterSyncCallback = () => console.log('onAfterSync - Financial closure initiated');56// Setup callback functions7component.setCallback('onBeforeSave', onBeforeSaveCallback);8component.setCallback('onAfterSave', onAfterSaveCallback);9component.setCallback('onAfterSync', onAfterSyncCallback);1011component.close();1213// Phase is set to "ToBeFinanciallyClosed"14// onBeforeSaveCallback is executed15// Data is saved to Salesforce16// onAfterSaveCallback is executed17// Promotion is synchronized to Processing Services18// onAfterSyncCallback is executed19// 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
1component.selectTactic('a37TC00000014j8YAA');23// 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 promise23// Create callback functions4const onBeforeSaveCallback = (data) => {5 return new Promise((resolve, reject) => {6 window.setTimeout(() => {7 resolve();8 }, 2000);9 });10};11const onErrorCallback = (error) => console.log('onError', error);1213// Setup callback functions14component.setCallback('onBeforeSave', onBeforeSaveCallback);15component.setCallback('onError', onErrorCallback);1617component.save();1819// onBeforeSaveCallback is executed20// Process wait the returned promise is resolved21// Data is saved to SFDC22// Save process continues2324// Rejected promise2526// Create callback functions27const 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);3536// Setup callback functions37component.setCallback('onBeforeSave', onBeforeSaveCallback);38component.setCallback('onError', onErrorCallback);3940component.save();4142// onBeforeSaveCallback is executed43// Process wait the returned promise is resolved44// Promise is rejected45// 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 baseline4 {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);23// After executing, the TPM UI will set the promotion into edit mode45component.setEditMode(false);67// 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
1component.setParticipatingCustomers([ // Array of items2 {3 "included": true, // Is Included?4 "externalid": "Supermarkets" // External id of the Participating Customer5 }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);23// After executing, the TPM UI will open the PL Grid filters45component.setPLGridFilterOpen(false);67// 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
1component.setPromotionAttachmentLinks([ // An array of objects2 {3 IsNew: false, // Flag to indicate if the record is new4 IsDeleted: false, // Flag to indicate if the record is deleted5 Id : 'a40TC00000014j8YAA', // Record id of the Promotion Attachment Link record6 cgcloud__Promotion_Attachment__c: 'a41TC00000014j8YAA', // Record attribute. 7 // Reference to the Promotion_Attachment__c record8 // All Tactic Fund record fields will be present as attributes9 ...10 },11 ...12]);
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 objects2 {3 IsNew: false, // Flag to indicate if the record is new. Promotion attachments cannot be flagged as new4 IsDeleted: false, // Flag to indicate if the record is deleted. Promotion attachments cannot be flagged as deleted5 Id : 'a41TC00000014j8YAA', // Record id of Promotion Attachment record6 cgcloud__Description_Language_1__c: 'Sample Attachment', // Record attribute. Reference to the Promotion_Attachment__c record7 // All Tactic Fund record fields will be present as attributes8 ...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([ // Array2 '01t17000001siy5AAA' // Product2 Id referencing a Category record3]);
setPromotionField
Sets a promotion SObject field.
API Version
55
Signaturei
setPromotionField(field, value)
Example Implementation
1component.setPromotionField(2 'cgcloud__Slogan_Language_1__c', // Field name3 'Test Slogan' // value4);
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.
Note
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
1// Import the TPMManualInput class to create new instances2import { TPMManualInput } from 'cgcloud/tpmGenericUtils';34...56// In this method, we will be adding a new manual input to the grid.7// This can, for instance, be executed in the click of a button or after8// some user interaction9async addNewManualInputs() {10 const tpmPromotion = this.template.querySelector('cgcloud-tpm-promotion');1112 // Extract the current manual inputs13 const currentManualInputs = tpmPromotion.getProperty('manualInputs');1415 // You can read information from the current manual inputs:16 currentManualInputs.forEach((mi) => {17 console.log(mi.getKPICode()); // 'ABCD'18 console.log(mi.getPeriodDateFrom()); // Date19 console.log(mi.getPeriodDateThru()); // Date20 console.log(mi.ProductId()); // '01tXXXXXXXXXXXXXXX'21 console.log(mi.getValue()); // 12322 });2324 // Example: KPI code to set the manual input to25 const kpiCode = 'ABCD';2627 // Example: Product Id to set the manual input to. If null,28 // the manual input will be applied to the "Total" for the KPI29 // productId can be any level on the product hierarchy that is part of 30 // the calculation (SubCategory, Brand, etc)31 const productId = '01tXXXXXXXXXXXXXXX';3233 // Methods used to extract data from the grid require the grid to be in valid34 // status. If you try to extract data from the grid when not in the correct status,35 // an exception will be thrown36 if (tpmPromotion.getProperty('calculationStatus') !== 'VALID') {37 throw new Error('Grid not in VALID status');38 }3940 // Extract the periods information from the grid41 const periods = await tpmPromotion.getPeriods();4243 // We find the period where we want to set the manual input.44 // You can find periods by name or use the periods "dateFrom, "dateThru" and "periodtype"45 // attributes to search for an specific period.46 // In this example, we will set the manual input on the "Total" period47 // that uses a specific label48 const manualInputPeriod = periods.find((p) => p.periodtype === 'Total');4950 // Create a new instance51 const newManualInput = new TPMManualInput({52 kpiCode: kpiCode,53 period: manualInputPeriod,54 productId: productId,55 value: 123 // Value to set56 });5758 // Create a new array with our new manual input appended59 const newManualInputArray = [...currentManualInputs, newManualInput];6061 // Set the manual inputs62 tpmPromotion.setPromotionManualInputs(newManualInputArray);6364 // After setting the new manual inputs, the grids will be automatically65 // reloaded and re-rendered with the new values in place.6667 // At this point, manual inputs are still not saved to SFDC database.68 // the user must save the promotion69}
setSubAccounts
Lists the objects with the SubAccounts format.
API Version
55
Signature
setSubAccounts(subAccounts)
Example Implementation
1component.setParticipatingCustomers([ // Array of items2 {3 "volume": 50, // Percent of volume for this sub account. 4 // Sum of included sub accounts volume must be 100 or less5 "included": true, // Is Included?6 "externalid": "Supermarkets" // External id of the SubAccount7 }8]);
setTacticConditionCreationDefinitions
Sets the related tactic condition creation definition records to the promotion.
1component.setTacticConditionCreationDefinitions([ // An array of objects2 {3 IsNew: false, // Flag to indicate if the record is new4 IsDeleted: false, // Flag to indicate if the record is deleted5 Id : 'a50TC00000014j8YAA', // Record id6 cgcloud__Tactic__c: 'a37TC00000014j8YAA', // Record attribute. 7 // All Tactic condition creation definition record fields will be present as attributes8 ...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 set3 'cgcloud__Comment__c', // Field name4 'Sample Tactic' // value5);
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.
Note
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 objects3 {4 IsNew: false, // Flag to indicate if the record is new5 IsDeleted: false, // Flag to indicate if the record is deleted6 Id : 'a38TC00000014j8YAA', // Record id7 cgcloud__Fund__c: 'a39TC00000014j8YAA', // Record attribute. Reference to the Fund__c record8 cgcloud__Tactic__c: 'a37TC00000014j8YAA', // Record attribute. Reference to the Tactic__c record9 // All Tactic Fund record fields will be present as attributes10 ...11 },12 ...13]);
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.
Note
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.