Generate new queue items

I have a process in which the input excel structure is the one I attached.

The dispatcher uploads each of the rows as a queue item, with its transportId and deliveries.

The deliveries field can have up to 1000 elements separated by ;. I have attached an example of input excel.

I need that when there are more than 200, I raise them to the queue with the same transportId and in groups of 200 I attach an example of how the queue elements should go.
inputExcel.xlsx (8.5 KB)
itemQueueExample.xlsx (9.5 KB)

Assign Activity
dtResult = dtOrig.Clone

Assign Activity
dtResult =

(From d In dtData.AsEnumerable
Let idt = d("idTransport")
From sgm In d("Deliveries").toString.Trim.Split(";"c).Chunk(200)
Let ra = New Object(){idt, String.Join(";", sgm)}
Select r = dtResult.Rows.Add(ra)).CopyToDataTable

I have entered it like this:
(From d in dtData.AsEnumerable
Let idt = d(“idTransport”)
from sgm in d(“Deliveries”).toString.Trim.Split(“;“c).Chunk(200)
Let ra = new Object(){idt, String.Join(”;”, sgm}
Select r = dtResult.Rows.Add(ra)).CopyToDataTable)

and it gives me an error: The expression gives me an error, it says that a comma was expected.
Thank you for your help.

refer to above fixed statement

I have put like this
(From d In dtOrigin.AsEnumerable
Let idt = d(“idTransport”)
From sgm In d(“Deliveries”).toString.Trim.Split(“;“c).chunk(200)
Let ra = New Object(){idt, String.Join(”;”, sgm)}
Select r = dtResult.Rows.Add(ra)).CopyToDataTable

Where dtOrigin is the name of my input table and it gives me the following error:
chunck is not a member of system.array

then you are working on a project with compatibility set to Legacy?

In such case we would rewrite to:

(From d In dtOrigin.AsEnumerable
Let idt = d("idTransport")
Let ars = d("Deliveries").toString.Trim.Split(";"c)
Let sgc = CInt(Math.Ceiling(ars.Length / 200))
From sgm In Enumerable.Range(0,sgc).Select(Function (c) ars.Skip(c*200).Take(200) )
Let ra = New Object(){idt, String.Join(";", sgm)}
Select r = dtResult.Rows.Add(ra)).CopyToDataTable
1 Like

Works!!!

Thank you a lot.

Sorry, one more question if my input Excel has 2 more columns, as in the example and I need all the data in all the columns.

How do I add them with this code?

I attach an example of my input excel. Thank you
inputExcel.xlsx (8.6 KB)

It depends higly on structures. Just open a new topic for further assistance for your new question

Preview:

(From d In dtOrigin.AsEnumerable
Let idt = d("idTransport")
Let ars = d("Deliveries").toString.Trim.Split(";"c)
Let sgc = CInt(Math.Ceiling(ars.Length / 200))
From sgm In Enumerable.Range(0,sgc).Select(Function (c) ars.Skip(c*200).Take(200) )
Let ra1 = New Object(){idt, String.Join(";", sgm)}
Let ra2 = d.ItemArray.Skip(2)
Let ra = ra1.Concat(ra2).Cast(Of Object).ToArray
Select r = dtResult.Rows.Add(ra)).CopyToDataTable
1 Like

Thank you a lot. WorK!!

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