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

Concatenating string with data element value

Avatar

Avatar
Validate 1
Level 2
sebastiane27965
Level 2

Likes

8 likes

Total Posts

40 posts

Correct Reply

3 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 1
Affirm 3
View profile

Avatar
Validate 1
Level 2
sebastiane27965
Level 2

Likes

8 likes

Total Posts

40 posts

Correct Reply

3 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 1
Affirm 3
View profile
sebastiane27965
Level 2

10-09-2020

Hi guys, i want to load a script with dynamic values based on domain, so i have set up a data element with the different values based on document.locationHostname, it seems to work as expected and the value changes based on site domain.
running into some issues when trying to load the string in the HTML custom code of rule.

 

so this is the string, it will fail at the getVar portion of the string:

<script src='https://sripturl/rc/'+(_satellite.getVar('account_string')+'/scripts/s.js' type='text/javascript'></script>  

 

so what im after is a string that looks like this (given the data element value is 12345):

<script src='https://sripturl/rc/12345/scripts/s.js' type='text/javascript'></script>  

 

i guess theres some single double quotation issues here, or maybe its not possible to do? 
Any pointers appreciated!

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Publish 1
MVP
yuhuisg
MVP

Likes

183 likes

Total Posts

564 posts

Correct Reply

107 solutions
Top badges earned
Publish 1
Affirm 100
Springboard
Bedrock
Validate 1
View profile

Avatar
Publish 1
MVP
yuhuisg
MVP

Likes

183 likes

Total Posts

564 posts

Correct Reply

107 solutions
Top badges earned
Publish 1
Affirm 100
Springboard
Bedrock
Validate 1
View profile
yuhuisg
MVP

10-09-2020

There are a few problems, e.g. you have an opening "(" but no corresponding closing ")". But the main problem is that you're mixing HTML and JavaScript together.

I suggest using this JavaScript code instead:

var script = document.createElement('script');
script.src = 'http://sripturl/rc/' + _satellite.getVar('account_string') + '/scripts/s.js';
script.type = 'text/javascript'; document.getElementsByTagName('head')[0].appendChild(script);

Reference: https://stackoverflow.com/a/18784960

Answers (0)