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
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Use dynamic variables in JS query def?

Avatar

Level 3

Hi all! 

I am attempting to build a way to access the most recent mirrorUrl of the latest sent email from a defined array of emails. This is to display to internal stakeholders so that we can always see the latest version that was sent on a daily basis. For that I am fiddling with JS to fetch that mirrorUrl from an array of deliveryCodes. 

I am struggling with using the variables from my array inside the queryDef itself - Not sure if it is possible or just me who is just getting blind towards that syntax? However, hopefully someone would be able to help me out here!

This is my code so far: 

var deliveries = ["'play_can_v1_eml__all_'","'play_dow_v1_eml___'","'tv2_onb_v1_eml_2_a_'","'play_win_v3_eml_3_a.a_'"];
var mirrorUrls = [];

for each (var del in deliveries){
var querySet = "\"[delivery/@deliveryCode]=\""+del;
  var query = xtk.queryDef.create(
    <queryDef schema="nms:broadLogRcp" operation="select" lineCount="1">
        <select>
            <node expr="@id"/>
            <node expr="@eventDate"/>
            <node expr="[delivery/@id]"/>
            <node expr="[delivery/@deliveryCode]"/>
        </select>
        <where>
            <condition expr="[delivery/@deliveryCode]="+del+""/>
        </where>
        <orderBy>
            <node expr="@eventDate" sortDesc="true"/>
        </orderBy>
    </queryDef>
    )

var res = query.ExecuteQuery()
mirrorUrls.push(nms.delivery.GetMirrorURL(del.@id, @ID));
}

It gives me the following error: 

11/07/2022 17:11:34 JST-310000 Error while compiling script 'PWKF5147/js' line 16: invalid XML tag syntax (line=' <condition expr=[delivery/@deliveryCode]="+del+""/> ' token='+del+""/> ').

 

So it looks like it is not able to evaluate the dynamic variable?

 

Hope that someone can help out here 🙂 Thanks! 

1 Accepted Solution

Avatar

Correct answer by
Level 4

Hello @SorenDahk,

 

It should look like this : 

 

<queryDef schema="nms:broadLogRcp" operation="select" lineCount="1">
        <select>
                      ...
        </select>
        <where>
            <condition expr={"[delivery/@deliveryCode]="+del}/>
        </where>
                         ...
    </queryDef>

 

Br,

Amine

View solution in original post

2 Replies

Avatar

Correct answer by
Level 4

Hello @SorenDahk,

 

It should look like this : 

 

<queryDef schema="nms:broadLogRcp" operation="select" lineCount="1">
        <select>
                      ...
        </select>
        <where>
            <condition expr={"[delivery/@deliveryCode]="+del}/>
        </where>
                         ...
    </queryDef>

 

Br,

Amine