Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 25064

Comparing numbers and IDs to join lists

$
0
0

I have two lists which I am trying to show as a composite list in a single view

So I have the first list, Orders for example, which contains basic data for an order (Customer, address etc) and of course an ID field
I have a second list, order items for example, containing the items ordered, itemID, quantity and OrderID. OrderID is a copy of the ID from the orders list.

Now in SQL to find for sake of an example everyone who ordered a widget is a simple LEFT JOIN and that's what I want to show in a composite view in Sharepoint. So I have ceated a page through sharepoint designer with a data source which is a linked data source between the two lists. However when I show the list no linked data appears. Specifically all the subview columns appear as "There are no items to show in this view".

After some tinkering it appears that although the ID column in orders is an integer, when it is copied to the second list it is no longer an integer so the comparison fails. What I am doing is;

//Create an order
SPListItem order = OrderList.Items.Add();
order["somedata"] = somedata;
order.Update();
int orderid = order.ID;

//Create the order items
SPListItem orderitem = OrderItemsList.Add();
orderitem["somedata"] = somedata;
orderitem["orderid"] = orderid; // has this forgotten it's an integer?
orderitem.Update();
//Loops and error checking etc obviously removed from that example.

If I show the composite view then I get "There are no items to show in this view" for the subview columns. If I link the ID of Orders to the ID or OrderItems I get data, albeit the wrong data. If I show the ID and OrderID of the OrderItems in the columns then I see a format difference. Specifically while the ID might be shown as "7" the OrderID appears as "3.0000000000" which suggests that in copying the ID it has changed from an integer to a real number which then fail to match.

If I change the code to;

//Create an order
SPListItem order = OrderList.Items.Add();
order["somedata"] = somedata;
order.Update();
int orderid = order.ID;
order.OrderID = orderid; // Break all normalisation rules and duplicate the ID field!
order.Update();

//Create the order items
SPListItem orderitem = OrderItemsList.Add();
orderitem["somedata"] = somedata;
orderitem["orderid"] = orderid; // has this forgotten it's an integer?
orderitem.Update();
//Loops and error checking etc obviously removed from that example.

ie. Having added OrderID as a column in the Order list I copy the ID for a list item to another field in the same list item and then link the lists using that OrderID column then it works. So the logic in the composite view is correct it would appear that copying a number from one column to another changes the underlying datatype. So what is the underlying data type for the ID field and how can I create a list column with a matching data type?

Can anyone suggest what on Earth I am doing wrong here (bearing in mind that I am absolutely new to SharePoint development)

With thanks in advance for any help.




Viewing all articles
Browse latest Browse all 25064

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>