Add related Product to Dynamic Content gets error "Obje

Posted by Community Admin on 04-Aug-2018 10:05

Add related Product to Dynamic Content gets error "Object must implement IConvertible"

All Replies

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

I have model like this. A CLIENT has a related data called FORMATION which based on Product. I need to add this FORMATION to related data field in CLIENT by code (not on GUI in back-end). So here the code i have done. 

-------------------

Guid id = new Guid();

            bool tryParse = Guid.TryParse(FormationId, out id);

            if (tryParse)
           
                DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
                Type clientType = TypeResolutionService.ResolveType(CpModuleClrType.Client);
                DynamicContent clientItem = dynamicModuleManager.GetDataItems(clientType).Where(c => c.GetValue<string>(ClientField.Nom) == "name").First();

                // This is how values for the properties are set

               // Gets error by this line     

                clientItem.SetValue(ClientField.Favoris, new List<Guid> id );

                // We can now call the following to publish the item
                ILifecycleDataItem publishedArtistsItem = dynamicModuleManager.Lifecycle.Publish(clientItem);

                //You need to set appropriate workflow status
                clientItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Published");

                // You need to call SaveChanges() in order for the items to be actually persisted to data store
                dynamicModuleManager.SaveChanges();
           

------------

The Guid id is the id of a particular formation. When i run this, it keeps getting error "Object must implement IConvertible."

 

I have tried another way fix this by replacing SetValue by CreateRelation. There was no Error but it didn't save the formation.

 

How could i change this code to make it works?

Thanks.

Posted by Community Admin on 04-Jul-2016 00:00

Hi,

You may refer to the below articles from our documentation and check the 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
 

This thread is closed