Script: Class dw.alert.Alerts

Class Alerts

Allow creation, removal, re-validation and retrieval of alerts that might get visible to Business Manager users.

The alerts have to be registered by the 'alerts.json' descriptor file in a cartridge assigned to the Business Manager site. The descriptor file itself has to be defined in 'package.json' of that cartridge using a property 'alerts' and providing its path that is relative to the 'package.json'. The 'alert.json' descriptor files contain the 'alert descriptions', which are referenced by their ID throughout the API.

For example, the 'alerts.json' file could have the following content:

{ "alerts": [ { "alert-id": "missing_org_config", "menu-action": "global-prefs_custom_prefs", "message-resource-id": "global.missing_org_config", "priority": "ACTION", "remediation": { "pipeline":"GlobalCustomPreferences", "start-node":"View" } }, { "alert-id":"promo_in_past", "menu-action":"marketing_promotions", "context-object-type":"Promotion", "message-resource-id":"promotion.in_the_past", "priority":"WARN", "remediation": { "pipeline":"ViewApplication", "start-node":"BM", "parameter":"screen=Promotion" } } ] }

The referenced menu actions can be found in the 'bm_extensions.xml' file of a Business manager extension cartridge (a sample file containing all current menu entries is provided when creating a new extension cartridge in Studio).

Constructor Summary

This class does not have a constructor, so you cannot create it directly.

Method Summary

static addAlert(alertDescriptorID : String, params : String...) : void

Creates a new alert for the given ID.

static addAlert(alertDescriptorID : String, contextObject : PersistentObject, params : String...) : void

Creates a new alert for the given ID and context object.

static addAlert(alertDescriptorID : String, contextObjectID : String, params : String...) : void

Creates a new alert for the given ID and ID of the context object.

static getAlerts(alertDescriptorIDs : String...) : List

Retrieves all alerts for a set of alert descriptor ID.

static getAlertsForContextObject(contextObjectID : String, alertDescriptorIDs : String...) : List

Retrieves all alerts for a set of alert descriptor ID and the given context object ID.

static getAlertsForContextObject(contextObject : PersistentObject, alertDescriptorIDs : String...) : List

Retrieves all alerts for a set of alert descriptor ID and the given context object.

static removeAlert(alertDescriptorID : String) : void

Removes all alerts for the given alert descriptor ID.

static removeAlert(alertDescriptorID : String, contextObject : PersistentObject) : void

Removes the alert for the given alert description and context object.

static removeAlert(alertDescriptorID : String, contextObjectID : String) : void

Removes the alert for the given alert description and context object ID.

static revalidateAlert(alertDescriptorID : String, processFunction : Function, params : String...) : void

Re-evaluates the process function, and creates or removes the respective alert.

static revalidateAlert(alertDescriptorID : String, contextObject : PersistentObject, processFunction : Function, params : String...) : void

Re-evaluates the process function, and creates or removes the respective alert.

static revalidateAlert(alertDescriptorID : String, contextObject : Object, contextObjectID : String, processFunction : Function, params : String...) : void

Re-evaluates the process function, and creates or removes the respective alert.

Methods inherited from class Object

assign, create, create, defineProperties, defineProperty, entries, freeze, fromEntries, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, getPrototypeOf, hasOwnProperty, is, isExtensible, isFrozen, isPrototypeOf, isSealed, keys, preventExtensions, propertyIsEnumerable, seal, setPrototypeOf, toLocaleString, toString, valueOf, values

Method Detail

addAlert

static addAlert(alertDescriptorID : String, params : String...) : void

Creates a new alert for the given ID. If such an alert already exists, no new one is created, and the existing one is not modified.

Parameters:

alertDescriptorID - the ID of the referenced alert description

params - parameters which may be shown in the alert message

addAlert

static addAlert(alertDescriptorID : String, contextObject : PersistentObject, params : String...) : void

Creates a new alert for the given ID and context object. If such an alert already exists, no new one is created, and the existing one is not modified. Multiple alerts for the same alert descriptor ID may exist, as long as they reference different objects. To refer to the same alert afterwards (e.g. to remove the alert) the same object must be provided.

Parameters:

alertDescriptorID - the ID of the referenced alert description

contextObject - the context object

params - parameters which may be shown in the alert message


addAlert

static addAlert(alertDescriptorID : String, contextObjectID : String, params : String...) : void

Creates a new alert for the given ID and ID of the context object. If such an alert already exists, no new one is created, and the existing one is not modified. Multiple alerts for the same alert descriptor ID may exist, as long as they reference different objects. To refer to the same alert afterwards (e.g. to remove it) the same object ID must be provided. Use this method when the alerts refers to an object which is not a PersistentObject.

Parameters:

alertDescriptorID - the ID of the referenced alert description

contextObjectID - the ID of the referenced object

params - parameters which may be shown in the alert message


getAlerts

static getAlerts(alertDescriptorIDs : String...) : List

Retrieves all alerts for a set of alert descriptor ID.

Parameters:

alertDescriptorIDs - the IDs of the referenced alert descriptions

Returns:

the list of alerts (of type Alert)


getAlertsForContextObject

static getAlertsForContextObject(contextObjectID : String, alertDescriptorIDs : String...) : List

Retrieves all alerts for a set of alert descriptor ID and the given context object ID.

Parameters:

contextObjectID - the ID of the referenced object

alertDescriptorIDs - the IDs of the referenced alert descriptions

Returns:

the list of alerts (of type Alert)


getAlertsForContextObject

static getAlertsForContextObject(contextObject : PersistentObject, alertDescriptorIDs : String...) : List

Retrieves all alerts for a set of alert descriptor ID and the given context object.

Parameters:

contextObject - the context object

alertDescriptorIDs - the IDs of the referenced alert descriptions

Returns:

the list of alerts (of type Alert)


removeAlert

static removeAlert(alertDescriptorID : String) : void

Removes all alerts for the given alert descriptor ID. This method will remove also alert referencing context objects, as long as they reference the same alert description.

Parameters:

alertDescriptorID - the ID of the referenced alert description


removeAlert

static removeAlert(alertDescriptorID : String, contextObject : PersistentObject) : void

Removes the alert for the given alert description and context object.

Parameters:

alertDescriptorID - the ID of the referenced alert description

contextObject - the context object


removeAlert

static removeAlert(alertDescriptorID : String, contextObjectID : String) : void

Removes the alert for the given alert description and context object ID.

Parameters:

alertDescriptorID - the ID of the referenced alert description

contextObjectID - the context object ID


revalidateAlert

static revalidateAlert(alertDescriptorID : String, processFunction : Function, params : String...) : void

Re-evaluates the process function, and creates or removes the respective alert. The process function must return true when the alert should be created, and false when it should be removed. When the process function states that the alert should be created, but it already exists, it is not created again. Instead, the existing alert is updated with the supplied parameters.

Parameters:

alertDescriptorID - the ID of the referenced alert description

processFunction - the validation function. Must return true when the alert needs to be created.

params - parameters which may be shown in the alert message


revalidateAlert

static revalidateAlert(alertDescriptorID : String, contextObject : PersistentObject, processFunction : Function, params : String...) : void

Re-evaluates the process function, and creates or removes the respective alert. The context object is handed as the only parameter to the process function. The process function must return true when the alert should be created, and false when it should be removed. When the process function states that the alert should be created, but it already exists, it is not created again. Instead, the existing alert is updated with the supplied parameters.

Parameters:

alertDescriptorID - the ID of the referenced alert description

contextObject - the context object for which the validation is done, might be null

processFunction - the validation function. Must return true when the alert needs to be created.

params - parameters which may be shown in the alert message


revalidateAlert

static revalidateAlert(alertDescriptorID : String, contextObject : Object, contextObjectID : String, processFunction : Function, params : String...) : void

Re-evaluates the process function, and creates or removes the respective alert. When the optional context object is supplied, it is handed as the only parameter to the process function (if its not supplied, no parameter is given to the function). The process function must return true when the alert should be created, and false when it should be removed. When the process function states that the alert should be created, but it already exists, it is not created again. Instead, the existing alert is updated with the supplied parameters. Use this variant of the function when the context object is not a persistent object. In this case the ID to be assigned to the alert must be supplied as an additional parameter. (Either both the context object and the ID must be provided, or none of them)

Parameters:

alertDescriptorID - the ID of the referenced alert description

contextObject - the context object for which the validation is done

contextObjectID - the id of the context object for which the validation is done (and which is used to add / remove the alert object)

processFunction - the validation function. Must return true when the alert needs to be created.

params - parameters which may be shown in the alert message