How to query related data (pages) from sitefinity dynamic mo

Posted by Community Admin on 04-Aug-2018 13:54

How to query related data (pages) from sitefinity dynamic module by api

All Replies

Posted by Community Admin on 09-May-2017 00:00

Hi All,

I have created a dynamic module in sitefinity and it contains 2 fields, a Title and a related data (Pages).I am searching for a couple of days how to query the related data pages by using dynamic module manage api .If any one have some sample code please share. The code that i have shared is given below.But I didn't get any results, instead i am getting different exceptions.

var dynamicProduct = DynamicModuleManager.GetDataItems(productType)
                    .FirstOrDefault(item => item.Status == ContentLifecycleStatus.Live && item.Visible == true &&
                    item.UrlName == urlName);

            if(dynamicProduct!=null)
           

                // first approach
                PageManager productLayoutManager = PageManager.GetManager();
                var prodayoutItem = productLayoutManager.GetPageNodes().FirstOrDefault(p => p.Id == SystemManager.CurrentContext.CurrentSite.HomePageId);

                //second approach
                var relatedpage = dynamicProduct.GetRelatedItems(Constants.HexionProduct.ProductLayout) != null ?
                    (PageNode)dynamicProduct.GetRelatedItems(Constants.HexionProduct.ProductLayout).FirstOrDefault() : null;

                //third approach
                IDataItem productLayoutItem = dynamicProduct.GetRelatedItems("ProductLayout").FirstOrDefault();
                if (productLayoutItem != null)
               
                    // This is how we get related parent items (of type Product)
                    //IDataItem productLayoutParentProductItem = productLayoutItem.GetRelatedParentItems("Telerik.Sitefinity.DynamicTypes.Model.HexionProducts.Product").FirstOrDefault();
                    // This is how we delete a relation
                    var page = productLayoutItem;
                    if (page != null)
                        layoutUrl = page.GetDefaultUrl();
               


               
           


Regards

Ajai

This thread is closed