Call a rule via Custom code of a rule | Community
Skip to main content
Pablo_Childe
Community Advisor
Community Advisor
June 4, 2024
Solved

Call a rule via Custom code of a rule

  • June 4, 2024
  • 2 replies
  • 1505 views

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.
Best answer by bjoern__koth

@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

 

2 replies

Jennifer_Dungan
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
June 4, 2024

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.

Jennifer_Dungan
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
June 4, 2024

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.

Pablo_Childe
Community Advisor
Community Advisor
June 5, 2024

Thanks Jennifer

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

bjoern__koth
Community Advisor and Adobe Champion
bjoern__kothCommunity Advisor and Adobe ChampionAccepted solution
Community Advisor and Adobe Champion
June 5, 2024

@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!
Pablo_Childe
Community Advisor
Community Advisor
June 5, 2024

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