I want display data in delivery template using instance variable | Community
Skip to main content
April 3, 2023
Solved

I want display data in delivery template using instance variable

  • April 3, 2023
  • 1 reply
  • 1466 views

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

 

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by ParthaSarathy

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

1 reply

ParthaSarathy
Community Advisor
ParthaSarathyCommunity AdvisorAccepted solution
Community Advisor
April 3, 2023

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); }
~  ParthaSarathy S~  Click here to join ADOBE CAMPAIGN USER GROUP for Quarterly In-person | Hybrid | Virtual Meetups
April 3, 2023

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?

ParthaSarathy
Community Advisor
Community Advisor
April 3, 2023

Refer this community thread to display workflow variables in delivery.

~  ParthaSarathy S~  Click here to join ADOBE CAMPAIGN USER GROUP for Quarterly In-person | Hybrid | Virtual Meetups