Expand my Community achievements bar.

SOLVED

xtk.queryDef.create Question

Avatar

Former Community Member

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
Former Community Member

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
Former Community Member

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

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----