Problem with xtk.queryDef with foreign key condition
Hello everyone,
I'm currenty trying to write a little piece of code which deletes all delivery logs that are linked to a cancelled delivery (or in some situations deliviers in "stop requested" state). The code first loads all delivieres which are in the specified states.
After that, I want to load all delivery logs which are linked to those deliveries (OT: I'm currently doing this by using 2 different database queries, because I don't know how to select data from 2 linked tabled with the xtk.queryDef, maybe somebody can give me some advises with this problem as well).
The problem with this is, that I can't query the foreign key in the schema "nms:broadlogrcp". The schema documentation tells me, that there is a foreign key called iDeliveryId. but when I try to use it in the xtk.queryDef (@deliveryID ??), I get an error that this field is unknown.
This is my code:
var deliveryQuery = xtk.queryDef.create(
<queryDef schema="nms:delivery" operation="select">
<select>
<node expr="@id"/>
<node expr="@internalName"/>
<node expr="@label"/>
</select>
<where>
<condition expr="@state=81"/>
</where>
</queryDef>)
var deliveryRes = deliveryQuery.ExecuteQuery()
var idArr = []
for each (var delivery in deliveryRes.delivery)
{
idArr.push(delivery.@id)
}
var logsQuery = xtk.queryDef.create(
<queryDef schema="nms:broadlogrcp" operation="select">
<select>
<node expr="@id"/>
<node expr="@DeliveryId"/>
</select>
<where>
<condition expr={"@DeliveryId IN ('" + idArr.join("', '") + "')"}/>
</where>
</queryDef>)
var logRes = logsQuery.ExecuteQuery()
What is the best practice on this problem?
Thanks in advance for any advices
Best Regards
Alex
