Developer forum

Forum » Development » How to retrieve item values from an area with the API

How to retrieve item values from an area with the API

Allan Iversen
Reply

Hey,

This is probably a simple question, but how do I retrieve the item field values defined by my item type on an area with the API?

What I want is to retrieve these values from my eg. content module running on a specific area.

Could you provide an example for this?

- Allan


Replies

 
Morten Bengtson
Reply

Try this...

var item = Dynamicweb.Frontend.PageView.Current().Item;
var value = item["myfield"];

EDIT: Sorry, this was for retreiving valuse from the Page item, not the area item.
 
Allan Iversen
Reply

Hey Morten,

 

Thanks for your help, but...

 

Dynamicweb.Frontend.PageView.Current().Item is null :-)

 

I would expect that both the item type system name and item field system name would be necessary for looking up the value. It would be possible have more than one item field with same system name cross item types, right?

 

Any other ideas?

 

- Allan

 
Allan Iversen
Reply

Hi again,


I found a bit more.


The Area object on the page view contains the item type system name defined on the area.


How do I retrieve the value from the item type system name and my item field system name?


What about the Dynamicweb.Content.Items namespace? Dynamicweb.Content.Items.Item.GetItemById return an Item type, but with my item type and item field, it returns null.

 

I'm not sure that this is right approach.

 

- Allan

 
Mikkel Ricky
Reply
This post has been marked as an answer

You have to get the area item yourself from the item storage using values from the area:

var pageView = Dynamicweb.Frontend.PageView.Current();
var item = Dynamicweb.Content.Items.ItemManager.Storage.GetById(Dynamicweb.Base.ChkString(pageView.Area.get_Value("AreaItemType")), Dynamicweb.Base.ChkString(pageView.Area.get_Value("AreaItemId")));

Best regards,
Mikkel


 

Votes for this answer: 1
 
Allan Iversen
Reply

Hey Mikkel,

Ahh, I see! It works.

Thanks for your help.

 

- Allan

 

You must be logged in to post in the forum