Developer forum
E-mail notifications
Item relation list returns a single value instead of an array of multiple values

Replies










Hi Pernille,
That ID is the ID of the List. You will need to use the API to get the elements of that list, but keep in mind that the APi will return the IDs of the Items attached to that list. Which means you might need an additional conversion from ItemId to the actual Item before you can access the Item properties.
I have used something like this in the past:
var customList = ItemList.GetItemListById(customListID);
Combined with :
foreach(var item in customList){ Dynamicweb.Content.Items.Item tempItem = Dynamicweb.Content.Items.Item.GetItemById("DiscountsImages", item); }
There might be better alternatives in newer versions of DW.
I hope this helps.
Adrian











Hi Pernille,
I have given you incomplete information.
The foreach should be done against a Relations property:
foreach(var item in treeList.Relations){
...
}
I am sorry I missed that. I have not used it in a while :)
Adrian

Thank you. It works! :)
Here is the code I used in order to get the field values of my item relation list items (for anyone stumbling upon this thread in the future):
foreach(var item in treeList.Relations){
Dynamicweb.Content.Items.Item myItem = new Dynamicweb.Content.Items.Item(item);


Hi Pernille,
You should be able to do this
var customList = ItemList.GetItems(customListID);
foreach(var item in customList){ // the 'item' var is already your item }
That makes it simper than having to go through the relations and then get each individual item.
Best Regards,
Nuno Aguiar










Nuno's alternative is a lot more elegant and efficient.
I will update my code to use his instead.
Thank you Nuno!
Adrian


You are welcome!
You must be logged in to post in the forum