Related content is null after added by api CreateRelation

Posted by Community Admin on 04-Aug-2018 03:45

Related content is null after added by api CreateRelation

All Replies

Posted by Community Admin on 20-Jun-2016 00:00

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();

Posted by Community Admin on 23-Jun-2016 00:00

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
 

This thread is closed