Launch: set a data element from within a rule? | Community
Skip to main content
Level 2
November 28, 2018
Solved

Launch: set a data element from within a rule?

  • November 28, 2018
  • 13 replies
  • 15495 views

How can I set a data element (I have it created as a custom code data element) from a rule? Basically I want the rule to fire when a user clicks a certain tile (there's a row of tiles with links). The following javascript figures out which tile it is and then tries to set the data element, but it's not working. tileIndex is correct, but the data element (featuredTileNumber) isn't getting set.

var tileIndex = $('.feature-tile-container .feature-tile .feature-tile-container__read-more-action .analytics-featuretitle-event').index(this)+1;

_satellite.logger.info('tile index= ' + tileIndex);

_satellite.setVar("featuredTileNumber",tileIndex);

_satellite.getVar("featuredTileNumber");

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 Stewart_Schilling

Are you saying that you have three ACTIONs in sequence?

Custom Code >> AA Set Variables >> AA Send Beacon

If so, then yes - it is a timing issue.  Custom Code runs asynchronously so the dynamic data element is not ready in time.

My suggestion (mentioned above) is slightly different.

In the CONDITIONs of your rule, create a Custom Code condition that sets your dynamic data element.  This will be sequentially executed (since condition MUST be evaluated first in order to determine if the rule actions are to be executed).

Then in your ACTIONs sequence, remove the custom code action, but keep the AA actions as-is.

Save, build, test, and report be in with your results.

13 replies

Stewart_Schilling
Community Advisor
Stewart_SchillingCommunity AdvisorAccepted solution
Community Advisor
December 5, 2018

Are you saying that you have three ACTIONs in sequence?

Custom Code >> AA Set Variables >> AA Send Beacon

If so, then yes - it is a timing issue.  Custom Code runs asynchronously so the dynamic data element is not ready in time.

My suggestion (mentioned above) is slightly different.

In the CONDITIONs of your rule, create a Custom Code condition that sets your dynamic data element.  This will be sequentially executed (since condition MUST be evaluated first in order to determine if the rule actions are to be executed).

Then in your ACTIONs sequence, remove the custom code action, but keep the AA actions as-is.

Save, build, test, and report be in with your results.

Level 2
April 24, 2023

This didn't work for me, when I added my code in the 'CONDITION', the rule didn't fire at all. My code checks if a button is clicked and sets the corresponding member in the xdm object. 

 

document.querySelector('#buy').addEventListener('click', function () {

    MyObject["clickAction"] = "set";

})

 

I don't see the rule being fired 

Level 2
December 5, 2018

Thank you so much! That was it and it's working now. Seriously, I appreciate the effort to help me out. Also learned that you can't use spaces in the Custom Link name field.

Stewart_Schilling
Community Advisor
Community Advisor
December 5, 2018

Great to hear it!  Glad I could help. -Stew