I want display data in delivery template using instance variable
I have a data schema name rec:dailyJokesList that contains fields id, setup, punchline and general and has around 70 records I am running a campaign workflow to send out one joke at a time on daily basis for which I want to access the value of attributes. I wrote this code in query activity and access jokes but when I am running the logInfo I am unable to see the values. It is showing empty values. Moreover i am getting all joke at once which should not be a case. Here is the code.
if (!instance.vars.joke) {
instance.vars.joke = {};
}
var query = xtk.queryDef.create(
<queryDef schema="rec:dailyJokesList" operation="select" startLine="1" lineCount="1">
<select>
<node expr="@id"/>
<node expr="@type"/>
<node expr="@setup"/>
<node expr="@punchline"/>
</select>
<orderBy>
<node expr="random()"/>
</orderBy>
</queryDef>
);
logInfo("Script started");
try {
var result = query.ExecuteQuery();
logInfo("Query result: " + result);
if (result!=null) {
var jokeRecord = result;
logInfo("JokeRecord: " + jokeRecord);
logInfo("Punchline:" + jokeRecord.@punchline);
instance.vars.joke.id = jokeRecord.@id;
instance.vars.joke.type = jokeRecord.@type;
instance.vars.joke.setup = jokeRecord.@setup;
instance.vars.joke.punchline = jokeRecord.@setup;;
logInfo("Joke id: " + instance.vars.joke.id);
logInfo("Joke type: " + instance.vars.joke.type);
logInfo("Joke setup: " + instance.vars.joke.setup);
logInfo("Joke punchline: " + instance.vars.joke.punchline);
} else {
logWarning("No jokes found");
}
} catch (e) {
logError("An error occurred: " + e.message);
}
logInfo("Instance variable exists: " + !!instance.vars.joke);