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

Forums / Developing with Sitefinity / Related content is null after added by api CreateRelation

Related content is null after added by api CreateRelation

2 posts, 0 answered
  1. Duc
    Duc avatar
    3 posts
    Registered:
    10 May 2016
    20 Jun
    Link to this post

    I add a related content to a dynamic content. I can see the result in Edit Mode. Wwhen I query data in code, I get a null. But when I re-publish content in Edit Mode, I can get the related content normally. What's wrong with my code? Can you help me?

     Here my code:

    var fund = dcm.CreateDataItem(fundType);
                        fund.SetValue("Title", string.Format("{0} - {1} - {2}", g.Key, f.Plan, f.Option));
                        fund.SetValue("AMFI", f.AMFI);
                        fund.SetValue("NAVOption", new TrackedList<Guid>() { optionTaxo.Taxa.Where(t => t.Name == f.Option).Single().Id });
                        fund.SetValue("NAVPlan", new TrackedList<Guid>() { planTaxo.Taxa.Where(t => t.Name == f.Plan).Single().Id });
                        fund.CreateRelation(scheme.Id, dcm.Provider.Name, "Telerik.Sitefinity.DynamicTypes.Model.DSPWidgets.SchemesListing", "Scheme"); 
                        if (fundManagerByAMFI.ContainsKey(f.AMFI))
                        {
                            var manager = fundManagers.Where(fm => fm.GetValue<Lstring>("Name").ToLower() == fundManagerByAMFI[f.AMFI].ToLower()).FirstOrDefault();
                            if (manager != null)
                            {
                                fund.CreateRelation(manager, "FundManager");
                            }
                        }
                        dcm.Lifecycle.Publish(fund);
                        fund.SetWorkflowStatus(dcm.Provider.ApplicationName, "Published");

    dcm.SaveChanges();

  2. Sabrie Nedzhip
    Sabrie Nedzhip avatar
    534 posts
    Registered:
    02 Dec 2016
    23 Jun
    Link to this post
    Hello,

    Please check the below articles from our documentation where there are samples for creating item relations: 

    http://docs.sitefinity.com/example-related-datarelated-data-api-examples

    http://docs.sitefinity.com/for-developers-related-data-api

    Regards,
    Sabrie Nedzhip
    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