Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

xtk.queryDef.create Question

Derek1092
Level 2
Level 2

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

1 Accepted Solution
Derek1092
Correct answer by
Level 2
Level 2

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

View solution in original post

3 Replies
Derek1092
Correct answer by
Level 2
Level 2

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

View solution in original post

Raj_bounteous
Community Advisor
Community Advisor

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

Jyoti_Y
Community Advisor
Community Advisor

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