Edit and Access Rights for Toolbar Buttons
Show, hide, or disable toolbar buttons in the TPM Trade Planning Lightning web component (LWC) by reading and overriding their edit and access rights (EAR) codes. An EAR override can't enable a button that the component disables for other reasons, such as missing promotion create access.
Required Editions
| Available in: Lightning Experience |
| Available in: Enterprise, Unlimited, Einstein 1, and Agentforce 1 Editions with Consumer Goods Cloud Trade Promotion Management |
Every toolbar action button except Debug in the TPM Trade Planning LWC
(cgcloud-tpm-trade-planning) has an edit and access rights (EAR) code that
controls whether the button is visible and editable. Read or override the EAR state through
the @api methods on cgcloud-tpm-trade-planning. The
component routes each call to the correct business object (BO) by the code prefix, so your
code never selects a BO.
- Codes that start with
TP_go to the Trade Calendar BO. - Codes that start with
AP_go to the Account Plan BO.
EAR Methods
The TPM Trade Planning LWC provides three @api methods for EAR codes.
isVisible(code)- Returns
trueor
for the EAR visibility of the button. Returns undefined if the target BO isn't ready yet.false
reports the EAR state only, so it can returnisVisible(code)truefor a button that isn't displayed. isEditable(code)- Returns
trueorfalsefor the EAR editability of the button. Returnsundefinedif the target BO isn't ready yet.isEditable(code) reports the EAR state only. It doesn't account for availability conditions, so it can return true for a button that's disabled.
setEARight(code, { visible, editable })- Overrides the visibility, editability, or both for the button.
The value that isVisible(code) and isEditable(code)
return is the override, if one exists, or the BO's default rules. A return value of
undefined means that the target BO isn't ready, which is different from
an explicit false.
How EAR Overrides Work
You can set visible, editable, or both in setEARight().
visible: falseremoves the button from the DOM.editable: falsedisables the button. The button stays on the page, but clicking it does nothing.
An override can force a button to be disabled, but it can't force a button to be enabled.
An editable: false override always wins, so the button stays disabled even
if the BO later updates a related state flag. For example, setEARight('TP_REFRESH',
{ editable: false }) keeps the Refresh button disabled regardless of other
state.
An editable: true override only clears the EAR block. It doesn't re-enable
a button that an availability condition, such as enablePrint or
hasPromotionCreateAccess, has turned off.
Each override stores both flags for a code. If you pass only one flag, the other flag keeps its current override value, or true if the code has no override yet. The BO's default rules no longer apply to that code.
EAR Override Persistence
EAR overrides are stored as page state on each BO, routed by the code prefix. An override lasts as long as its BO is mounted, including across view switches.
A TP_ override stays on the Trade Calendar BO when a user switches from
Trade Calendar to Account Plan, and it applies again when the user returns to Trade
Calendar.
To restore a button, call setEARight(code, { visible: true, editable: true
}), or pass only the flag that you overrode, such as { visible: true
} or { editable: true }. Restoring a flag writes an explicit
true value. It doesn't revert the button to the BO's default rules.
When a user opens the Account Plan, its business object (BO) remains mounted, even after returning to the Trade Calendar. Call setEARight for AP_ codes after the user navigates to Account Plan. Calls made before then are ignored, and a warning is logged to the browser console.
EAR Codes and the Buttons They Control
When no override exists, the BO resolves the visibility and editability of each button. If
the BO doesn't resolve a value, both visibility and editability fall back to
true.
Some buttons also have an availability condition. A button is disabled when either its EAR state or its availability condition disables it. This table lists each EAR code, the button that it controls, any availability condition, and the effect of an override.
| EAR Code | Button | Availability Condition | Override Effect |
|---|---|---|---|
TP_REFRESH |
Refresh, on both Trade Calendar and Account Plan | On Account Plan only, Refresh is enabled only when the grid has unsaved changes and the calculation status is Reload. | Hides or disables the button. Doesn't enable the button when the condition isn't met. |
TP_FILTER |
Filter on Trade Calendar | None | Hides or disables the button. |
TP_VIEW_CONTROLS |
View controls (gear) on Trade Calendar | None | Hides or disables the button. |
TP_PRINT |
enablePrint |
Hides or disables the button. editable: true doesn't enable
the button when enablePrint is false. |
|
TP_PL |
P&L, which opens Account Plan | canAccessPL |
Hides or disables the button. Doesn't enable the button when
canAccessPL is false. |
TP_COPY_PROMOTION |
Copy Promotions | enableCopyPromotion and
hasPromotionCreateAccess |
By default, enableCopyPromotion is true only when both Copy
Promotions and printing are enabled in the calendar configuration. |
TP_NEW_PROMOTION |
New Promotion on Trade Calendar | hasPromotionCreateAccess |
Hides or disables the button. Doesn't enable the button when the condition is
false. |
AP_DOWNLOAD |
Download | The Download button appears only on Account Plan, and only when Account Plan - Enable Download Button is on. Disabled while the grid is downloading or loading, or when the grid data has an ERROR or EMPTY status. | Hides or disables the button. Doesn't enable the button when a condition blocks it. |
AP_NEW_PROMOTION |
New Promotion on Account Plan | hasPromotionCreateAccess |
Hides or disables the button. Doesn't enable the button when the condition is
false. |
AP_FILTER |
Filter on Account Plan | None | Hides or disables the button. |
AP_VIEW_CONTROLS |
View controls (gear) on Account Plan | None | Hides or disables the button. |
This JavaScript sample hides the Refresh button, disables the Print button, reads their
state, restores both buttons, and hides the Account Plan Download button. The
getApi() accessor in your custom wrapper, which is the Lightning web
component that contains cgcloud-tpm-trade-planning, returns the
cgcloud-tpm-trade-planning component. The accessor locates it by
data-id. The AP_DOWNLOAD call uses the same method as the Trade
Calendar calls because the component routes it to the Account Plan BO.
const api = this.getApi(); // <cgcloud-tpm-trade-planning>, located by data-id
// Hide Refresh entirely
api.setEARight('TP_REFRESH', { visible: false });
// Disable Print without removing it
api.setEARight('TP_PRINT', { editable: false });
// Read state
api.isVisible('TP_REFRESH'); // false
api.isEditable('TP_PRINT'); // false
// Restore both
api.setEARight('TP_REFRESH', { visible: true });
api.setEARight('TP_PRINT', { editable: true });
// Account Plan codes route to the Account Plan BO automatically.
// Call this after the user has navigated to Account Plan at least once.
api.setEARight('AP_DOWNLOAD', { visible: false });
