Dynamic content type with status ContentLifecycleStatus.Live is not returning RelatedData but ContentLifecycleStatus.Master is working fine.
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.
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