More in this section

Forums / Developing with Sitefinity / How to query related data (pages) from sitefinity dynamic module by api

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

1 posts, 0 answered
  1. Ajai
    Ajai avatar
    15 posts
    Registered:
    02 Mar 2015
    09 May
    Link to this post

    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

1 posts, 0 answered