Update Datatable based on dictionary

Hello

I have a datatable of shipping and corresponding order numbers as well as an empty column final num

Order, Shipping,FinalNum
1234, 552455,
1234, 9935399,
5678, 003500,

I convert this to a dictionary where I now have the orders that have multiple shipping numbers because i need to process them together

for ex: {“1234”,{“552455”,“9935399”}…}

after the processing, i will get a final num per order and i need to update the table accordingly.

So for example

Order, Shipping,FinalNum
1234, 552455, 555
1234, 9935399, 555
5678, 003500, 777

Now, how can i update my datatable each time in the following loop, right after the last workflow (has the finalnumber in output)

so for example my order is “1234” and ShippingsArray is {“552455”,“9935399”}

image

I have thought about using lookup but is there anything lighter ?

Thanks a lot

Hi @adext

Try this:

For Each item in orderToShippingDictionary
    Assign finalNumber = 677 (Get the final number for the current order here)
        If row("Order").ToString() = item.Key
            Assign row("FinalNum") = finalNumber

1 Like

Hi,

I think it’s better to have the dictionary including datarow in advance.
For example, using the following expression.

dict = dt.AsEnumerable.GroupBy(Function(r) r("Order").ToString).ToDictionary(Function(g) g.Key,Function(g) Tuple.Create(g.Select(Function(r) r("Shipping").ToString).ToArray(),g.Select(Function(r) r).ToArray))

This way we can easily write to the finalnum to datatable just after calculated, in the loop.
Can you try the following sample?

Sample
Sample20231014-1aL.zip (3.4 KB)

Regards,

2 Likes

hello Yoichi,

thank you for always coming with helpful suggestions!
to give a bit more info, i am trying to use this datatable to trace my progress in case of retry, here is the resume: Making a custom retry

In the end I decided to use a datatable + all the other columns. so to be more precise, my datatable would actually have more columns. so something like this

Order, Shipping,FinalNum, step2, step3, …
1234, 552455,
1234, 9935399,
5678, 003500,

will this solution still work? should i replace the whole “tracing” datatable with a dictionary in this case?

@adext

To update multiple rows at the same time…you can use the following in the invoke code activity with dt as the in/out argument and pass the datatable

dt.AsEnumerable.Where(function(x) x("Order").ToString.Equals(OrderNumberVaraible)).ToList.ForEach(sub(r) r("FinalNum") = FinalNumberVariable)

Here replace orderNumebrVariable and FinalNumberVariable with actual values

cheers

1 Like

Hi Anil

Worked thank you!! :slight_smile:

1 Like

@adext

Glad it helped you.

Can you please close the topic if resolved

Cheers

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.