Fetching and storing data in variables in Web Applications | Adobe Higher Education
Skip to main content
Level 2
January 29, 2024
Beantwortet

Fetching and storing data in variables in Web Applications

  • January 29, 2024
  • 1 Antwort
  • 1424 Ansichten

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

Dieses Thema wurde für Antworten geschlossen.
Beste Antwort von Anushka_RK

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

 


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

1 Antwort

Manoj_Kumar
Community Advisor
Community Advisor
January 29, 2024

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
Level 2
January 29, 2024

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

Anushka_RKAutorAntwort
Level 2
February 1, 2024

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

 


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