Solved

arc:enum Can it take a dynamic range?


Userlevel 5
Badge +1

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..[output.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>[_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 :”

icon

Best answer by James B 3 July 2024, 21:45

View original

4 replies

Userlevel 5
Badge +1

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>[data.EventTime]</EventTime>
<OrderNo>[data.OrderNo]</OrderNo>
<CustomerOrderReference>[data.CustomerOrderReference]</CustomerOrderReference>
<StatusCode>[data.StatusCode]</StatusCode>
<StatusName>[data.StatusName]</StatusName>
<WaybillNo>[data.WaybillNo]</WaybillNo>
<Notes>[data.Notes]</Notes>
<SignedBy>[data.SignedBy]</SignedBy>
<Signature>[data.Signature]</Signature>
<Latitude>[data.Latitude]</Latitude>
<Longitude>[data.Longitude]</Longitude>
<PalletID>[_value|add(1)]</PalletID>
</OrderStatusUpdate>'
</arc:set>
</arc:if>

</arc:enum>

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

 

Userlevel 6
Badge

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? 

Userlevel 5
Badge +1

Thanks James

 

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

Userlevel 6
Badge

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 [output.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