Hello,
I want to insert a dynamic hyperlink into the mail. The hyperlinks will be inputted from a csv file. From some documentation I understand it has to be done while inserting a script.
Does anyone knows how this works?
with kind regards,
Arnoud Hageman.
First, I’m assuming you’re already using one datafile to get a basic data model and this is a second data file you’re working with.
There are probably better ways to do this. However, you can pull in the contents of that text file by using “loadhtml”
As an example:
var path = "file:///C:/temp/test.txt";
var text = loadhtml(path);
text = text + " MORE STUFF";
results.html(text);
This loads the contents of a text file located at c: emp est.txt, adds the words " MORE STUFF" to the very end of it, and displays it on the page. On my test document I got a cheerful little message of “test text MORE STUFF” displayed on my page when I ran this as a selector script.
You could use this to get the contents of that CSV file into the script as the variable text. After that, you can do anything you want with it. For ease of use, you’ll probably want to convert it to JSON (see here: IO Domains in Alexa Top 1 Million | techslides.com). Once you’ve got a json string in a variable, you’ve got a lot of powerful tools built into javascript for searching values in there and matching them up to your data. I’ll leave that to you, but this should at least get you started.
If your datafile holds the links you can do it with a script like the following.
Selector = id/class/text of your link element (e.g.: #dynamicLink)
Script:
var dynamicLink = “http://localhost:8080/” + record.fields.yourField;
query(“#dynamicLink”).attr(“href”,dynamicLink);
The script changes the link-attribute dynamically.