Skip to main content

In a Script connector, based on a value I’ve calculated earlier in the script (numberofpallets) , I need to repeat an XML structure multiple times. The only thing that changes is the <PalletID>

I’m trying this

 

<arc:set attr="output.data">
<arc:enum range="1..goutput.header:numberofpallets]">

<OrderStatusUpdate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<EventTime>2024-07-03T13:03:00.0000+01:00</EventTime>
<OrderNo>200766</OrderNo>

...

<Longitude>Not Available</Longitude>
<PalletID>t_index]</PalletID>
</OrderStatusUpdate>

</arc:enum>
</arc:set>

 

But get the error “Invalid range, e.g of valid ranges are 1..20, a..z, A..z, z..a etc :”

Okay, this is crude, but it works up to 99 pallets…

<arc:set attr="data.pallets" value=""/>

<arc:enum range="0..99">

<arc:if attr="output.header:numberofpallets" value="=_value]" operator="greaterthan">

<arc:set attr="data.pallets">
data.pallets]
<OrderStatusUpdate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<EventTime>tdata.EventTime]</EventTime>
<OrderNo>tdata.OrderNo]</OrderNo>
<CustomerOrderReference>tdata.CustomerOrderReference]</CustomerOrderReference>
<StatusCode>tdata.StatusCode]</StatusCode>
<StatusName>tdata.StatusName]</StatusName>
<WaybillNo>tdata.WaybillNo]</WaybillNo>
<Notes>tdata.Notes]</Notes>
<SignedBy>tdata.SignedBy]</SignedBy>
<Signature>tdata.Signature]</Signature>
<Latitude>tdata.Latitude]</Latitude>
<Longitude>tdata.Longitude]</Longitude>
<PalletID>t_value|add(1)]</PalletID>
</OrderStatusUpdate>'
</arc:set>
</arc:if>

</arc:enum>

<arc:set attr="output.data" value="<PalletsStatuses>tdata.pallets]</PalletsStatuses>"/>
<arc:push item="output"/>

 


You should be able to evaluate an expression just about anywhere including the range in an enum - this works for me:

 

<arc:set attr="output.header:numberofpallets" value="10" />
<arc:enum range="1...output.header:numberofpallets]">
<arc:set attr="output.filename" value=""_value].txt" />
<arc:push item="output" />
</arc:enum>

 

Are you sure that output.header:numberofpallets was set to an integer value earlier in the script? 


Thanks James

 

numberofpallets was calculated using | add()  so I presume it is an integer


Hi Russell,

 

Would you be able to provide the whole code here? I could not see where the value was initialized. You can always use arc:throw as a makeshift mechanism for stepping through the script:

 

<arc:throw code="x" desc="NumberOfPallets is soutput.header:numberofpallets | def('undefined')]" />

<arc:set attr="data.pallets" value=""/>

<arc:enum range="0..99">

<arc:if attr="output.header:numberofpallets" value="=_value]" operator="greaterthan">

If you do this, you’ll see an exception with the value that output.header:numberofpallets currently has - is that an integer?


Reply