Expand my Community achievements bar.

SOLVED

xtk.queryDef.create Question

Avatar

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

Avatar

Correct answer by
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

Avatar

Correct answer by
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

Avatar

Level 6

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

Avatar

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