Use dynamic variables in JS query def? | Community
Skip to main content
Level 4
July 11, 2022
Solved

Use dynamic variables in JS query def?

  • July 11, 2022
  • 1 reply
  • 1918 views

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, @1716897)); }

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! 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Amine_Abedour

Hello @sorendp,

 

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

1 reply

Amine_Abedour
Community Advisor
Amine_AbedourCommunity AdvisorAccepted solution
Community Advisor
July 11, 2022

Hello @sorendp,

 

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

Amine ABEDOUR
SorenDPAuthor
Level 4
July 12, 2022

@amine_abedour - That's it! Thank you so much 🙂