Can we store instance variable into an array? | Community
Skip to main content
saishag86196293
Level 1
Sep 17, 2018 12:43 PM UTC
Solved

Can we store instance variable into an array?

Using queryDef am fetching a no sql field (an XML say 'ctx') field. Is there is any way to store the results in the array and then use the enrichment so that I can add these variables to the final data?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
nainyjainAccepted solution
Employee
Sep 17, 2018 2:01 PM UTC

Hi saishag86196293 ,saishag86196293

You can store the query results in an array using for each loop in the query result and store it in vars to use it further in upcoming activities.

Below is the code text:

var query = xtk.queryDef.create( 

  <queryDef schema="xyz:transient" operation="select">   

    <select>     

      <node expr="@id"/>     

      <node expr="@campId"/>     

      <node expr="@recCount"/>   

    </select>       

  </queryDef>)

var res = query.ExecuteQuery()

//Creating array to store all Id's

id = []

for each (var t in res.transient){

id.push(t.@id)

}

logInfo('id array' + id);

//Store id array in vars to use it in next activities

vars.idArray = id;

logInfo('vars.idArray ' + vars.idArray);

Thanks,

Nainy Jain

3 replies

vraghav
Employee
Sep 20, 2018 6:28 AM UTC

Hi saishag86196293,

When you will try to access this in the next activity, the array automatically gets converted to a comma separated string and hence you will have to split the variable and regenerate the array.

Regards,
vipul

Translate
Level 4
Jul 13, 2022 10:08 AM UTC

Hi! I am just fiddling with a similar issue. Could you please elaborate upon how you would go about regenerating the array? And how do you reference items in an array in a delivery for instance? 

Translate
nainyjainAccepted solution
Employee
Sep 17, 2018 2:01 PM UTC

Hi saishag86196293 ,saishag86196293

You can store the query results in an array using for each loop in the query result and store it in vars to use it further in upcoming activities.

Below is the code text:

var query = xtk.queryDef.create( 

  <queryDef schema="xyz:transient" operation="select">   

    <select>     

      <node expr="@id"/>     

      <node expr="@campId"/>     

      <node expr="@recCount"/>   

    </select>       

  </queryDef>)

var res = query.ExecuteQuery()

//Creating array to store all Id's

id = []

for each (var t in res.transient){

id.push(t.@id)

}

logInfo('id array' + id);

//Store id array in vars to use it in next activities

vars.idArray = id;

logInfo('vars.idArray ' + vars.idArray);

Thanks,

Nainy Jain

Translate