Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

How to access data elements in custom code

Avatar

Avatar
Validate 1
Level 2
christopher2151
Level 2

Likes

9 likes

Total Posts

15 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 1
Applaud 5
View profile

Avatar
Validate 1
Level 2
christopher2151
Level 2

Likes

9 likes

Total Posts

15 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 1
Applaud 5
View profile
christopher2151
Level 2

25-05-2018

Is there a way to reference the data elements I have created inside a snippet of custom code in the code editor?

var bkprop4 = "%myDataElement%";

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Springboard
MVP
StewSchilling
MVP

Likes

339 likes

Total Posts

276 posts

Correct Reply

85 solutions
Top badges earned
Springboard
Bedrock
Validate 1
Establish
Contributor
View profile

Avatar
Springboard
MVP
StewSchilling
MVP

Likes

339 likes

Total Posts

276 posts

Correct Reply

85 solutions
Top badges earned
Springboard
Bedrock
Validate 1
Establish
Contributor
View profile
StewSchilling
MVP

25-05-2018

You bet you can.

var bkprop4 = _satellite.getVar("myDataElement");

The % signs are just for use in the UI.  They can also be used in HTML tags - I'm pretty sure that they trigger replacement during the rendering process.

You can also use _satellite.setVar("variableName", value) in your custom code, but only for new data elements.  You cannot change the value of a UI created data element using setVar.   I like to use a standard naming convention when I dynamically create data elements using _satellite.setVar.  This way I have no chance of conflicting with UI data elements.

One more point.  I often will create a data element in a rule's custom code and then reference it from the UI in an action.  When doing this, you need to manually enter it in the UI field (using the %name% notation as normal).

Answers (3)

Answers (3)

Avatar

Avatar
Springboard
MVP
StewSchilling
MVP

Likes

339 likes

Total Posts

276 posts

Correct Reply

85 solutions
Top badges earned
Springboard
Bedrock
Validate 1
Establish
Contributor
View profile

Avatar
Springboard
MVP
StewSchilling
MVP

Likes

339 likes

Total Posts

276 posts

Correct Reply

85 solutions
Top badges earned
Springboard
Bedrock
Validate 1
Establish
Contributor
View profile
StewSchilling
MVP

29-05-2018

No issues at all (as long as you don't intend to use that data element in the Launch UI.

On that note, I've been wanting to try the new Core Extension Event Type of (custom code) with an AJAX success handler.  This event type has the guidance, `The code you provide in the editor will be run as soon as the library is loaded. Inside your code, call trigger() whenever you would like the rule to fire.`

It seems that you could put your AJAX event listener as custom code and when you catch the event (or events) that you care about, call trigger().  You can also put a JSON object as a parameter in the trigger call, i.e. `trigger({key1:value1, key2:value2})`

Avatar

Avatar
Springboard
MVP
StewSchilling
MVP

Likes

339 likes

Total Posts

276 posts

Correct Reply

85 solutions
Top badges earned
Springboard
Bedrock
Validate 1
Establish
Contributor
View profile

Avatar
Springboard
MVP
StewSchilling
MVP

Likes

339 likes

Total Posts

276 posts

Correct Reply

85 solutions
Top badges earned
Springboard
Bedrock
Validate 1
Establish
Contributor
View profile
StewSchilling
MVP

25-05-2018

One more thing that might blow your mind is that although the UI expects a data element to return a string, you can store anything in them (Objects, Functions, Arrays, Strings, Numbers, Booleans). 

As an example:

_satellite.setVar( "dynPersonObj", {firstName: "stew", lastName: "schilling", age: "old"} );

_satellite.logger.log( "AGE is ", _satellite.getVar("dynPersonObj")[age] );

Maybe that's more than you wanted to know...

Avatar

Avatar
Validate 1
Level 2
christopher2151
Level 2

Likes

9 likes

Total Posts

15 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 1
Applaud 5
View profile

Avatar
Validate 1
Level 2
christopher2151
Level 2

Likes

9 likes

Total Posts

15 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 1
Applaud 5
View profile
christopher2151
Level 2

29-05-2018

stewarts16448458​ Thank you for the detailed response. Could you see an issue with creating a data element inside Launch that retrieves an JSON object from an Ajax call?