Developer forum

Forum » Development » Deleting items and creating items on website settings

Deleting items and creating items on website settings

Anders Ditlevsen
Anders Ditlevsen
Reply

Hey

I am currently trying to Retrieve and delete/create items on an itemList, which is located on the websites setting of this particular website in a dynamicweb solution.

I am able to acquire the itemList and loop through the items like this:

ItemList productList = ItemList.GetItemListById(ProductItemListID); // The id is known
string headline = product.FirstOrDefault( x => x.Key == "ProdOverskrift").Value?.ToString();


My questions are thus:

  1. To delete and item i can call .Delete() on the item, does this also remove the item for any itemList and clean up all the relations the item would've had? If it does not, then how can i delete the relation to the item? I cannot find any 'remove/delete' item on the ItemList, or on the itemList.Relations. 
  2. When creating an item i dont see any way to add the item to the relation list, or set the different fields values, as the values collection is read only. How do you do this?

I did not find anything useful in regards to question 1 or 2 on the item service, in terms of deleting or update relations. Maybe i am missing something?

BR
Anders Ditlevsen


Replies

 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply
This post has been marked as an answer

Hi Anders,

You can find some sample code in our API docs for the ItemList class.

https://doc.dynamicweb.com/api/html/31360718-d43b-666a-f062-f47a3740ef3f.htm

Is that what you need?

BR
Morten

Votes for this answer: 1
 
Anders Ditlevsen
Anders Ditlevsen
Reply

Hi Morten

That does help, thank you very much :)

I have an addional question though. When i create my item, then before i add it to my itemList i need to set some of the fields on it. I looked at the ItemEntry and Item documentation from the link you posted, and i did not see any methods to set a field. Normall i'd access the field directly on the key value pair collection, however the collection of fields is read only so i cannot modify them this way. Maybe i am missing something here aswell?

Is the only way to remove the field through the remove methods and then add it again through the add methods? Is it not possible to just change the value of already existing field?

BR
Anders

 
Vladimir Shushunov Dynamicweb Employee
Vladimir Shushunov
Reply
This post has been marked as an answer

Hi Anders,
ItemEntry is a base class - it usually doesn't used directly. Instead you could create  an code-first item (an example in https://doc.dynamicweb.com/api/html/d6a14638-4580-a1c9-3328-09ce262762f1.htm )

Or just use Item class: https://doc.dynamicweb.com/api/html/e1d55035-fb4a-e181-f43d-6c66d16fb864.htm to create an item of specified type.

Some examples to work with items:
http://doc.dynamicweb.com/training-certification/t3-platform-developer/t3-platform-developer/3-4-items

Best regards, Vladimir

Votes for this answer: 1
 
Anders Ditlevsen
Anders Ditlevsen
Reply

Thank you for the answers :)

BR
Anders

 

You must be logged in to post in the forum