cancel
Showing results for 
Search instead for 
Did you mean: 

How to properly read a Collection of Items?

Jacques-Antoine
Active Participant
0 Kudos

Hello ByD experts,

I am sure this a a really easy question for you.

I want to read two Item Lines in my Sales Order but I do not succeed in this by following the documentation of the studio.

What I want to do is to compare the Quantity of the first Item with the Quantity of the second Item in a Sales Order.

I got the first Quantity with the GetFirst(), but I do not succeed to specifically select the second line item, that is to say the one with ItemID = "20".

I am sure there is a function for this or a type of query to do this, but I cannot find it. And I am having trouble trying to use the Where() clause with the ItemID.

Here is my sample code I did to try what I need:

Thank you everybody for you attention and help!

Best regards.

Jacques-Antoine

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Jacques-Antoine,

What are you trying to accomplish here?

While you're welcome to use whatever terminology you want when coding, i think you may be confusing yourself to some degree. A SalesOrder.QueryByElements is return instances of the SalesOrder root node, not any particular item node.

If you want to loop through Sales Orders and the items within the Sales Orders, i'd use nested foreach statements.

e.x.

foreach (var FoundSalesOrder in QuerySalesOrderResults) {

     foreach (var FoundItem in FoundSalesOrder.Item) {

          //Your Code Here

     }

}

Still, this seems to assume that you're only ever dealing with two line Sales Orders, which would appear to be a pretty specific use-case. A little more background would help us determine a better approach to use.

Jacques-Antoine
Active Participant
0 Kudos

Hello Dan,

Thank you for your quick answer!

So, yes, I have a very specific use-case where I only need the two first line for each Sales Order to be compared.

What I need is to compare the Qty of the first line item, ItemID = 10 , to the Qty of the second line item, ItemID = 20. And raise a message if they are not equal.

The problem is I do not know how to make sure I get the second line and compare it to the first.

So i wanted to create two variables which hold the two Quantities. And compare this two variables.

I did the Query on the Sales order ID because I thought I could drill down the Query Results as with the Query Execution and the navigation by association. So going from the Root Node to the Item Node.

I wanted to do a Where clause, like a Where(SalesOrder.Item.ID = "10") but i didn't find out how.

And as you said, I made a big mistake trying to find a collection in something unique as my query only returns the SalesOrder instance. I thought perhaps the instance of the SalesOrder would return all the instance of the items in this Sales Order. I was certainly wrong. Moreover the terms I used are really misleading actually.

I will try the nested foreach and will get back to you asap!

Thank you very much Dan!

Sincerely.

Jacques-Antoine