Developer forum

Forum » Development » Find ItemTypes value for a specific Area

Find ItemTypes value for a specific Area

Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi guys,

I am making my debut in working with Code First ItemTypes.

One of my cases requires that I create an ItemType relation list (Inline) that will add some values in the database.

Separately, I need to be able to use those values in another DropDown list.

The problem I have is how to select them just for the current Area.

If I use the regular way, I can only list the Items that are set as Pages and/or paragraphs, which is not my case.

I can also try to select them using SQL but It might be a complex SQL since I have to filter them just for the current Area.

Is anybody having another approach on a more elegant and efficient way to do accomplish my goal?

Thank you,

Adrian


Replies

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply
This post has been marked as an answer

Hi Adrian,
maybe you could use the Dynamicweb.Content.Items.Activation.ActivationManager.Current.GetAllowedItemsForArea method for that purpose.
Regards, Dmitrij

Votes for this answer: 1
 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Thank you Dmitrij.

That's exaclty what I needed.
Adrian

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Dmitriy,

I gave it a try but apparently that method is not what I needed. It solves another need, which is good, but not my original problem.

That method returns the ItemTypes that are allowed in the Area. What I need, are the instances of a specific ItemType for a specific Area. And the return should be a list of ItemType objects.

Does it make sense?

Thank you,

Adrian

 
Nicolai Pedersen
Reply

Hi Adrian

You would have to find all pages with that item type attached to it in a specific area using a combination of the pageservice and some LINQ. Then when you have a collection of items from that area, you need to find the values of each of the item fields of that type.

Alternatively you have to go to SQL and join Page, ItemList, ItemListRelation and item_{systemname} to find the right values...

The latter is probably the best performing.

BR Nicolai

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

My hope was that you guys have already figured out an easier way to do it :)

In this case, let me ask a different question that might help in this case.

What if I define ahidden gield in the ItemType and save the area ID in it when the page (or paragraph) is created?

Do I have a way to read the AreaID that the item is created into from the ItemType definition?

This way I can always filter by the AreaID stored on the Item record.

What do you think?

Thanks,

Adrian

 
Nicolai Pedersen
Reply

Maybe - not sure I fully understand.

You can create the field with the areaid. There will be one for each record. But reading that information from the itemtype definition I do not understand - the itemtype would have many instances of the item with different areaid...? But you want to find the area context of the current item editing? It could be possible using ExecutingContext.IsBackend() and see what is in the querystring of page/paragraph ids...

BR Nicolai

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

My problem is that I will have a version of an ItemType for each Language area.

To explain briefly, I have an ItemType holding some Details about a product. Each ItemType record is related to a Product and and Area (becuse of language specificity).

This ItemType has amn ItemRelation field that I want to be populated with values of another ItemType defined for that specific Area.

That's why I need a flexible and accesible way to read the AreaId.

If I can store the AreaId where the ItemType is created, in a Hidden field (called AreaId), it will make my life easier and the relation between the items might potentially be more efficient.

But his means I need a way to determine the AreaID in the "get set" definition for that hidden field.

I see that the Method above can tell me if I am executing the action from the Backend but I am not sure how I would get the AreaId. I see there is a method for getting the Culture but nothing about getting the URL parameters.

I guess I could use the regular .NET methods for getting the AreaID from querystring?

Thank,
Adrian

 
Nicolai Pedersen
Reply

Hi Adrian

Yes, you can use regular querystrings.

BR Nicolai

 

You must be logged in to post in the forum