xtk.queryDef.create Question

Derek1092

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)

Derek1092

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)

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

rajbounteous

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