Loop Issue

Hi,

I have a requirement where I need to loop thru a doc list(oreder items) in a Purchase Order.
Multiple number of order are permissible.

As an example:

Target sysetm acceptes only 10 orders at a time …

  1. If the number of orders are less than 10. (< 10)

I need to set the value for two strings as New=Y and AI=N
(this can be done in a map statement)
appenedthe docuemnte list —> make it a string and send to target system

  1. If the number of orders are more than 10 (> 10)

lets thinks there are 32 orders…

Round1 : Orders 1 - 10 Set New=Y AI=Y
@@@append the document list —> make it a string and send to a function which behaves differently basing on the New, AI values

Round2 : Orders 11 - 20 Set New=N AI=Y
@@@appened the docuemnte list —> make it a string and to a function which behaves differently basing on the New, AI values

Round3 : Orders 21 - 30 Set New=N AI=Y
@@@appened the docuemnte list —> make it a string and send to to a function which behaves differently basing on the New, AI values

Round4 : Orders 31 - 32 Set New=N AI=N
@@@appened the docuemnte list —> make it a string and send to to a function which behaves differently basing on the New, AI values

My doubt – After sending the Round1 Order, I need to clean up the documents list and again use the same doc list for Round2 Order and need to send the

Else please let me know how to go about this type of issues…

Regards,
Sunny

Unless there is some hard reason not to, would sending in just 1 order at a time work? That would simplify the solution. Sending in 10 at a time would presumably be more efficient but many times that extra efficiency doesn’t matter.

Hello,
Well you would need a toggle to know when you reach a certain threshold. I am assuming each order is a seperate entry in a string list.

get the length of the list. you will start with a top level branch, split on whether you have %length% <10> 10. The first option you know how to do and is easy.

The second option will require you to have two counters. one will start at zero and work up to your max number of records. the other will store the round you are on. you will loop over the entire list, append to order entry to a temp list. branch when the %counter% >= maxValue. then in a sequence, you will set your other values you need, send the data, delete the temp list, reset the counter to zero, update round to next. make sure your counter incrementor is just outside this branch but still in the loop. So a quick mock is:

map {get orderlist length -> len}
branch {eval label}

  • seq{len < 10}
    – map {do less than ten work}
  • seq {len > 10}
    – map {counter = 0, round = 0}
    – loop {orderlist}
    — branch {eval label}
    ---- seq {counter >= 10}
    ----- map {round -> round + 1, counter = 0}
    ----- branch {round}
    ------ seq {1}
    ------- map {new=y, ai=y}
    ------- map {do other stuff with tempList}
    ------ seq {2}
    ------- map {new=n, ai=y}
    ------ seq {3}
    ------- map {new=y, ai=n}
    ------ seq {4}
    ------- map {new=n, ai=n}
    ----- map {delete tempList}
    — map {appendToStringList -> orderlist[i] to tempList}
    — map {counter = counter + 1}
    – map {delete counter, round}
    map {delete len}

The pseudo should better explain what my sentences tried to tell you. That should be it. You will want to consult the DevelopersGuide, BuiltInServicesGuide, and searhing other previous posts for more information. Good day.

Yemi Bedu

Sunny,

Assuming that you must send the orders in batches of 10, you can certainly build a Flow that will meet your requirements. I have used a similar approach to avoid overwhelming a downstream system that had a (very small) number of available database connections.

Inside the outer loop use appendToDocumentList to build-up the batch of orders to send. Check a counter after each append and if the counter is greater than some configurable batch size, convert the docList to an XMLString and send it to the appropriate function to deliver to the target system. After this call returns successfully, reset your batch counter and drop the batch document list. Initialize your “New” and “AI” variables before entering your outer loop and then reset them after sending your first batch of orders.

After exiting the outer loop, send any orders in the batch document list. This will handle the final 2 orders in your example above and cases in which there are fewer than 10 orders to begin with).

Mark