Hello -
Do actions have a way to access their friendly name or other properties from within the action
Why?:
I have a rule "Fire OrderConfirm Events"
That rule contains 10 actions.
In each action, I'd like to call a function that checks the action reached "the end" and didn't error. If it does error, I'd want to surface the name of the action that errored
So instead of:
Rule Fire OrderConfirm Events Fired - followed by
unexpected: Undefined etc etc.
I can have it throw
"Action ${action.name} Failed" => "Action Pinterest Failed"
That way I can easily track errors in larger rules
Solved! Go to Solution.
Views
Replies
Total Likes
That is correct, sorry misread. Had a look at the source code of Adobe Launch and cannot see how to do it.
Having said that, we adopted the following standards when it comes to actions using custom code. We placed the code inside try/catch and we provide meaningful error logs, this way we are sure where the error originated from.
If your script has multiple parts and it is "ok" for a part to fail then add try/catch around each block to isolate their errors.
So either:
try { //action code } catch (e) { _satellite.logger.error('Failed in actionX', e) } //OR in case we want to isolate errors based on logical blocks function test() { try { //logical block one } catch (e) { _satellite.logger.error('Failed in actionX to send pixel XYZ', e) } try { //logical block two } catch (e) { _satellite.logger.error('Failed in actionX to inject surveyXYZ', e) } } test();
Actions (and also Events and Conditions) in a Rule have access to a "this". But the "this" refers to the object (usually the DOM object) that caused the Event to trigger. E.g. with a Click Event, the "this" refers to the DOM element that was clicked (as determined by the selector specified in the Event).
So the "this" won't work for your use-case. If you're using a Custom Code action, then you can wrap that custom code in a Promise and handle the failure on your own.
Yes I believe you can do it:
A second argument would then have to be passed to your module which contains the contextual information about the event that fires the rule. It may be beneficial in certain cases and can be accessed as follows:
module.exports = function(settings, event) { // event contains information regarding the event that fired the rule };
The event object must contain the following properties:
$type | A string describing the extension name and event name, joined using a period. For example, youtube.play. |
$rule | An object containing information about the currently executing rule. The object must contain the following sub-properties:
|
That is taken from the documentation to create your own extension but believe it or not, if the action or condition or event pass the `event` argument you can access the same using this code:
_satellite.logger.log(event.$rule.name)
However some extensions do not pass event argument by default, also you need to make sure to not select the `execute globally` checkbox as it will overwrite the this and event and target
Views
Replies
Total Likes
event.$rule.name returns the name of the rule, as implied in the object path.
But the question here is how to get an action's name. That can't be done with the method that you described.
Views
Replies
Total Likes
That is correct, sorry misread. Had a look at the source code of Adobe Launch and cannot see how to do it.
Having said that, we adopted the following standards when it comes to actions using custom code. We placed the code inside try/catch and we provide meaningful error logs, this way we are sure where the error originated from.
If your script has multiple parts and it is "ok" for a part to fail then add try/catch around each block to isolate their errors.
So either:
try { //action code } catch (e) { _satellite.logger.error('Failed in actionX', e) } //OR in case we want to isolate errors based on logical blocks function test() { try { //logical block one } catch (e) { _satellite.logger.error('Failed in actionX to send pixel XYZ', e) } try { //logical block two } catch (e) { _satellite.logger.error('Failed in actionX to inject surveyXYZ', e) } } test();
Views
Likes
Replies
Views
Likes
Replies