Related content is null after added by api CreateRelation - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Related content is null after added by api CreateRelation

  • Related content is null after added by api CreateRelation
  • 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();

  • Hello,

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

    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