Expand my Community achievements bar.

SOLVED

I want display data in delivery template using instance variable

Avatar

Level 1

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);

 

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @bhat_shivas ,

Try the below script to get one record in logInfo

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>
);

var result = query.ExecuteQuery();

for each (var jokeRecord in result)
{
logInfo("Script started");

instance.vars.jokeId = jokeRecord.@id;
instance.vars.jokeType = jokeRecord.@type;
instance.vars.jokeSetup = jokeRecord.@setup;
instance.vars.jokePunchline = jokeRecord.@punchline;

logInfo("Joke id: " + instance.vars.jokeId);
logInfo("Joke type: " + instance.vars.jokeType);
logInfo("Joke setup: " + instance.vars.jokeSetup);
logInfo("Joke punchline: " + instance.vars.jokePunchline);
}

View solution in original post

4 Replies

Avatar

Correct answer by
Community Advisor

Hi @bhat_shivas ,

Try the below script to get one record in logInfo

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>
);

var result = query.ExecuteQuery();

for each (var jokeRecord in result)
{
logInfo("Script started");

instance.vars.jokeId = jokeRecord.@id;
instance.vars.jokeType = jokeRecord.@type;
instance.vars.jokeSetup = jokeRecord.@setup;
instance.vars.jokePunchline = jokeRecord.@punchline;

logInfo("Joke id: " + instance.vars.jokeId);
logInfo("Joke type: " + instance.vars.jokeType);
logInfo("Joke setup: " + instance.vars.jokeSetup);
logInfo("Joke punchline: " + instance.vars.jokePunchline);
}

Avatar

Level 1

Hi, thank you. I am able to see data in logs. If now i have to display that data in recurring delivery using instance variable. How can i do that?

Avatar

Level 1

Hi @ParthaSarathy ,

I tried to display the workflow variable by following this link, but I am getting empty value. 

 

Here is the email screenshot. 

email screenshotemail screenshot I am able to see records in 

Screenshot (25).png

 

Here is the delivery template: 

Screenshot (26).png

Screenshot (27).png