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);
Solved! Go to Solution.
Views
Replies
Total Likes
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);
}
Views
Replies
Total Likes
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);
}
Views
Replies
Total Likes
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?
Views
Replies
Total Likes
Refer this community thread to display workflow variables in delivery.
Views
Replies
Total Likes
Hi @ParthaSarathy ,
I tried to display the workflow variable by following this link, but I am getting empty value.
Here is the email screenshot.
I am able to see records in
Here is the delivery template:
Views
Replies
Total Likes