Add related Product to Dynamic Content gets error "Object must implement IConvertible"
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.
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