+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Dynamic content type with status ContentLifecycleStatus.Live is not returning RelatedData but ContentLifecycleStatus.Master is working fine.

Dynamic content type with status ContentLifecycleStatus.Live is not returning RelatedData but ContentLifecycleStatus.Master is working fine.

2 posts, 0 answered
  1. Uttam
    Uttam avatar
    21 posts
    Registered:
    17 Mar 2015
    08 Jun 2015
    Link to this post

    Hi All,

    I imported some content from excel using Sitefinity API (Version 8.0) and in the Sitefinity backend everything looks fine and all the contents are added as Published status but when I'm trying to query the data then related data objects are coming as null for Live Status and working fine for Master status. Does anybody know why ?

    Adding Dynamic content to the system:

    var providerName = String.Empty;
                    using (var dynamicModuleManager = new DynamicModuleManager(providerName))
                    {
                        DynamicContent pointOfInterestItem = dynamicModuleManager.CreateDataItem(_pointOfInterestType);

                        // This is how values for the properties are set
                        pointOfInterestItem.SetValue("InternalTitle", title);
                        pointOfInterestItem.SetValue("Title", title);
                       

                        //add a ref to Exhibits content
                        if (_allExhibits != null && _allExhibits.Any())
                        {
                            string contentFilter = string.Format("Title.Equals(\"{0}\")", exhibitOrDistrict);
                            var exhibitItem = _allExhibits.Where(contentFilter).FirstOrDefault();
                            if (exhibitItem != null)
                            {
                                pointOfInterestItem.CreateRelation(exhibitItem, "Exhibit");
                            }
                        }

                        //add a ref to Point of interest type content by type field
                        if (_allPointOfInterestType != null && _allPointOfInterestType.Any())
                        {
                            string contentFilter = string.Format("Title.Equals(\"{0}\")", type);
                            var pointOfInterestTypeItem = _allPointOfInterestType.Where(contentFilter).FirstOrDefault();
                            if (pointOfInterestTypeItem != null)
                            {
                                pointOfInterestItem.CreateRelation(pointOfInterestTypeItem, "PointOfInterestType");
                            }
                        }

                        var urlName = Regex.Replace(title, @"[\\~#%&*{}/:<>?|""@ ]", "-").ToLower();
                        pointOfInterestItem.SetString("UrlName", urlName);

                        pointOfInterestItem.SetValue("Owner", SecurityManager.GetCurrentUserId());
                        pointOfInterestItem.SetValue("PublicationDate", DateTime.Now);
                        pointOfInterestItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Draft");
                        
                        // Save the changes
                        dynamicModuleManager.SaveChanges(); 

                        // Send the Item for approval
                        var bag = new Dictionary<string, string>();
                        bag.Add("ContentType", pointOfInterestItem.GetType().FullName);
                        WorkflowManager.MessageWorkflow(pointOfInterestItem.Id, pointOfInterestItem.GetType(), dynamicModuleManager.Provider.ToString(), "Publish", false, bag);

     

    Now query the data:

    var dynamicModuleMngr = new DynamicModuleManager();
                    var poiType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.PointofInterest.PointOfInterest");
                    var poiDataList = dynamicModuleMngr.GetDataItems(poiType);
                    if(poiDataList != null && poiDataList.Any())
                    {
                        string attractionType = "museum";

    //NOT working related data is coming as null
                        IEnumerable<DynamicContent> FilteredItems;
                        var reqGuidId = this.GetCategoryId(attractionType);

                        if (!string.IsNullOrEmpty(attractionType))
                            FilteredItems = poiDataList.Where(p => p.GetValue<TrackedList<Guid>>("attractiontypecategory").Contains(reqGuidId)
                                                         && p.Status == ContentLifecycleStatus.Live);
                        else
                            FilteredItems = poiDataList.Where(p => p.Status == ContentLifecycleStatus.Live && p.Visible == true);

                        foreach(var p in FilteredItems)
                        {
                            PointOfInterest item = new PointOfInterest();
                            item.Title = p.GetValue<Lstring>("Title");

                            //ExhibitOrDistrict
                            var exhibitData = p.GetRelatedItems<DynamicContent>("Exhibit").FirstOrDefault();
                            if (exhibitData != null)
                            {
                                item.ExhibitOrDistrict = exhibitData.GetValue<Lstring>("Title");
                            }                       
                        }


                        //Working fine
                        IEnumerable<DynamicContent> FilteredItems2;
                        if (!string.IsNullOrEmpty(attractionType))
                            FilteredItems2 = poiDataList.Where(p => p.GetValue<TrackedList<Guid>>("attractiontypecategory").Contains(reqGuidId)
                                                        && p.Status == ContentLifecycleStatus.Master);
                        else
                            FilteredItems2 = poiDataList.Where(p => p.Status == ContentLifecycleStatus.Live && p.Visible == true);

                        foreach (var p in FilteredItems2)
                        {
                            PointOfInterest item = new PointOfInterest();
                            item.Title = p.GetValue<Lstring>("Title");

                            //ExhibitOrDistrict
                            var exhibitData = p.GetRelatedItems<DynamicContent>("Exhibit").FirstOrDefault();
                            if (exhibitData != null)
                            {
                                item.ExhibitOrDistrict = exhibitData.GetValue<Lstring>("Title");
                            }                        
                        }
                    }

    Thanks for looking into my issue.​

     

     

     

  2. Svetoslav Manchev
    Svetoslav Manchev avatar
    735 posts
    Registered:
    06 Dec 2016
    11 Jun 2015
    Link to this post
    Hello Uttam,

    You can check this article:
    http://docs.sitefinity.com/for-developers-related-data-api

    Note also that the returned result contains a list with all related data items. The data items are in the same status as the related item, whose child or a parent they are.

    Regards,
    Svetoslav Manchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
2 posts, 0 answered