Call a rule via Custom code of a rule | Community
Skip to main content
Pablo_Childe
New Participant
Jun 4, 2024 6:35 PM UTC
Solved

Call a rule via Custom code of a rule

I was wondering if someone knew of the syntax that would allow me to fire a rule from within the custom code section of a rule.

 

thanks

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
bjoern__koth
bjoern__kothAccepted solution
New Participant
Jun 5, 2024 11:58 AM UTC

@pablo_childe 

How about a classic direct _satellite.track call and a rule listening to this direct call event?

 

_satellite.track('contact_submit', { name: 'John Doe' });

 

https://experienceleague.adobe.com/en/docs/experience-platform/tags/client-side/satellite-object

 

Cheers from Switzerland!

5 replies

bjoern__koth
bjoern__kothAccepted solution
New Participant
Jun 5, 2024 11:58 AM UTC

@pablo_childe 

How about a classic direct _satellite.track call and a rule listening to this direct call event?

 

_satellite.track('contact_submit', { name: 'John Doe' });

 

https://experienceleague.adobe.com/en/docs/experience-platform/tags/client-side/satellite-object

 

Translate
Cheers from Switzerland!
Pablo_Childe
New Participant
Jun 5, 2024 2:12 PM UTC

Thanks Bjoern
I sis happen to have a DCR on that rule so this will work appreciate the response.

Translate
Jennifer_Dungan
Level 2
Jun 4, 2024 9:12 PM UTC

While I don't know of code to directly call a rule.... if you have a rule set up to trigger based on a custom JS event, you could call the event from within custom code that would then cause the other rule to trigger, essentially resulting in the same final result....

 

 

 

So for instance, let's say I set up Rule A to trigger based on a custom code listener:

window.addEventListener('myCustomEvent', function (e) { trigger(); }, false);

 

 

 

Now, in Rule B, I want to run some logic to trigger Rule A. 

I'm going to assume that the event "myCustomEvent" isn't declared yet, so I will both declare and dispatch the event inside of Rule B

var myCustomEvent = new Event("myCustomEvent"); window.dispatchEvent(myCustomEvent);

 

As soon as I call the window.dispatchEvent for myCustomEvent, Rule A will trigger.

Translate
Jennifer_Dungan
Level 2
Jun 4, 2024 9:18 PM UTC

One more thing, for the record, I've never had a lot of luck using the "Custom Event" trigger in Launch... but I've had a lot more success with creating my own listeners, so I've been doing this for years...

 

So following the old adage: "stick with what works"

 

I mention this, cause I figured that will be the follow up comments as to why I didn't just use the Custom Event event type.

Translate
Pablo_Childe
New Participant
Jun 5, 2024 2:11 PM UTC

Thanks Jennifer

This solution is great in another case for me appreciate the response!

Translate