xtk.queryDef.create Question

Avatar

Avatar
Validate 1
Level 1
Derek1092
Level 1

Likes

2 likes

Total Posts

3 posts

Correct reply

1 solution
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile

Avatar
Validate 1
Level 1
Derek1092
Level 1

Likes

2 likes

Total Posts

3 posts

Correct reply

1 solution
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile
Derek1092
Level 1

11-10-2019

I have a query activity that feeds into a javascript code activity. One of the columns of data that I am feeding from the query uses an aggregate function: count(products_purchased). I am using xtk.queryDef api to write pull the results from the query and need to figure out how to pull this column in the following javascript code:

var query = xtk.queryDef.create(

     <queryDef schema={vars.targetSchema} operation="select"

          <select>

               <node expr={count(products_purchased)} />

          </select>

     </queryDef>

).ExecuteQuery();

for each( var row in query)

     logInfo("Total products purchased: " + row.count(products_purchased));

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Validate 1
Level 1
Derek1092
Level 1

Likes

2 likes

Total Posts

3 posts

Correct reply

1 solution
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile

Avatar
Validate 1
Level 1
Derek1092
Level 1

Likes

2 likes

Total Posts

3 posts

Correct reply

1 solution
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile
Derek1092
Level 1

11-10-2019

I think I figured it out. In the additional data column of the query where I added the aggregate function, I had an alias name. So when I call that column I need to do
<node expr="alias-name" />

...

row.alias-name

Answers (2)

Answers (2)

Avatar

Avatar
Boost 50
MVP
Jyoti_Y
MVP

Likes

89 likes

Total Posts

123 posts

Correct reply

55 solutions
Top badges earned
Boost 50
Shape 1
Boost 5
Give Back 5
Give Back 3
View profile

Avatar
Boost 50
MVP
Jyoti_Y
MVP

Likes

89 likes

Total Posts

123 posts

Correct reply

55 solutions
Top badges earned
Boost 50
Shape 1
Boost 5
Give Back 5
Give Back 3
View profile
Jyoti_Y
MVP

14-10-2019

Hi Derek,

Please use below script and it will give you output:

var query = xtk.queryDef.create( 

     <queryDef schema={vars.targetSchema} operation="select">

          <select> 

               <node expr="Count(@id)" alias="var1"/> 

          </select> 

     </queryDef> 

).ExecuteQuery(); 

 

 

for each( var row in query) 

     logInfo("Total products purchased: " + row.var1); 

Thanks,

Jyoti

Avatar

Avatar
Contributor
MVP
Raj_bounteous
MVP

Likes

90 likes

Total Posts

97 posts

Correct reply

32 solutions
Top badges earned
Contributor
Shape 1
Give Back 10
Give Back 5
Give Back 3
View profile

Avatar
Contributor
MVP
Raj_bounteous
MVP

Likes

90 likes

Total Posts

97 posts

Correct reply

32 solutions
Top badges earned
Contributor
Shape 1
Give Back 10
Give Back 5
Give Back 3
View profile
Raj_bounteous
MVP

11-10-2019

Hi,

check this code from the link

jobCount = NLWS.xtkQueryDef.create(
  <queryDef schema="nms:remaHypothesis" operation="get">
   <select>
   <node expr="Count(@id)" alias="@count"/>
   </select>
   <where>
   <condition expr={"@status="+HYPOTHESIS_STATUS_RUNNING}/>
   </where>
  </queryDef>)

iJobCount = iJobCount + parseInt(jobCount.ExecuteQuery().@count)

https://blog.floriancourgey.com/2018/08/use-querydef-the-database-toolkit-in-adobe-campaign