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

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
2 posts, 0 answered
  1. Duc
    Duc avatar
    3 posts
    Registered:
    10 May 2016
    20 Jun 2016
    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:
    17 Aug 2017
    23 Jun 2016
    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