コミュニティアチーブメントバーを展開する。

Submissions are now open for the 2026 Adobe Experience Maker Awards
解決済み

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

トピック

トピックはコミュニティのコンテンツの分類に役立ち、関連コンテンツを発見する可能性を広げます。

1 受け入れられたソリューション

Avatar

正解者
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

元の投稿で解決策を見る

6 返信

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

正解者
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