Expand my Community achievements bar.

Announcing the launch of new sub-community for Campaign Web UI to cater specifically to the needs of Campaign Web UI users!
SOLVED

Fetching and storing data in variables in Web Applications

Avatar

Level 2

Hi Team,

I have created a web application that redirects to anyone of the 4 landing pages based on certain criteria (OfferAcceptedPage, OfferExpiryPage, OfferDeclinePage, ErrorPage). There are 3 parameters (ParamKey1, ParamKey2, ParamLanguage) passed in the URL. I have also created 5 variables to hold the values for Key1, Key2, Language, Response and OfferExpiryDate.

 

I am fetching the required values using the below queryDef:

var res = xtk.queryDef.create(
<queryDef schema="nms:recipient" operation="select">
<select>
<node expr="[Table1/Key1]"/>
<node expr="[Table1/Key2]"/>
<node expr="[Table1/Language]"/>
<node expr="[Table1/OfferExpiryDate]"/>

<node expr="[Table2/Response]"/>

</select>
<where>
<condition expr={"[Table1/Key1]='"+ctx.var.ParamKey1+"' and [Table1/Key2]= '"+ctx.var.ParamKey2+"' and [Table1/Language] = '"+ctx.var.ParamLanguage+"'"}/>
</where>
</queryDef>).ExecuteQuery();

for each (var rcp in res)
{
ctx.vars.Key1 = rcp.Key1;
ctx.vars.Key2 = rcp.Key2;
ctx.vars.Language = rcp.Language;
ctx.vars.OfferDate = rcp.OfferExpiryDate;

ctx.vars.Response = rcp.Response;
}

Issue: In this case, I am able to see the values for ctx.vars.Key1, ctx.vars.Key2 and ctx.vars.Language (in the Preview tab debug mode). But the values for ctx.vars.OfferDate and ctx.vars.Response appear blank in the Web application. I have checked the table and it has values populated for both the fields. I have also tried testing the above queryDef in a JavaScript activity in a workflow, and I am able to view the values for ctx.vars.OfferDate and ctx.vars.Response. 

Query:

1. Can anyone please help me understand the reason for this behavior?

2. Is there any other way to fetch data for columns stored in linked tables within Web Application?

 

Thank you in advance.

 

Kind Regards,

Anushka R

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Level 2

Hi @Manoj_Kumar_,

 

I realized that I was using the parameter (instead of the variable that it is mapped to) in the where condition of the queryDef.

 

I made the change to my code to filter based on the mapping variables and I was able to fetch the required data.

 

Thank you for your support.

 

Kind Regards,

Anushka R

View solution in original post

6 Replies

Avatar

Community Advisor

Hello @Anushka_RK 

 

Try adding toString() in the values like this

 

ctx.vars.Key1 = rcp.Key1.toString();
ctx.vars.Key2 = rcp.Key2.toString();
ctx.vars.Language = rcp.Language.toString();

 

Also, If your query is returning 5 results then your ctx variables will have the value of the last iterated result.


     Manoj
     Find me on LinkedIn

Avatar

Level 2

Hi @Manoj_Kumar_ ,

 

Thank you for the quick response.

I tried adding .toString() to all the fields, but the values for ctx.vars.OfferDate and ctx.vars.Response are still empty. 

 

Kind Regards,

Anushka R

Avatar

Community Advisor

Hello @Anushka_RK 

 

Try to print the values first for all the results and see if the values exist or not.

for each (var rcp in res)
{
%>
<%= rcp.Key1 %> 
<%= rcp.Key2 %>
<%= rcp.Language %>
<%= rcp.OfferExpiryDate %>
<%= rcp.Response %>

<%
}
%>

 


     Manoj
     Find me on LinkedIn

Avatar

Level 2

Hi @Manoj_Kumar_ ,

 

I did check, and the values are empty for the two fields when I try to retrieve them within the JS activity in the Web Application. However, they hold data in the table.

I also ran the above queryDef in a JavaScript activity in a workflow and I am able to view all the values there. 

 

Kind Regards,

Anushka R

Avatar

Level 2

Hi @Manoj_Kumar_ ,

 

The values are not populating in the queryDef as the parameters used in the where clause are empty.

Was wondering if the syntax ("ctx.var.ParamKey1" or "ctx.vars.ParamKey1") to fetch the parameter variable defined in the queryDef is correct? Is there any other way to retrieve value in the parameter variable?

 

Kind Regards,

Anushka R

 

Avatar

Correct answer by
Level 2

Hi @Manoj_Kumar_,

 

I realized that I was using the parameter (instead of the variable that it is mapped to) in the where condition of the queryDef.

 

I made the change to my code to filter based on the mapping variables and I was able to fetch the required data.

 

Thank you for your support.

 

Kind Regards,

Anushka R