How to prevent duplicates when creating content items using the DynamicModuleManager's CreateDataItem() method
I created a module using the Module builder. Now I'm trying to programmatically add content items but I want to prevent duplicates, kind of the same way that you cannot add 2 content items with the same url if you add content from the content menu. Is there a best practice to accomplish this or do I need to loop through the collection and check manually?
When I programmatically add duplicate content items, set the same UrlName, call SaveChanges(), call Publsih() from ILifecycleDataItem and call SetWorkflowStatus() it doesn't throw any errors and then I end up with duplicates.
Jeff
Hello Jeff,
Thank you for contacting us.
You are correct, you need to make sure that an item with the same url does not already exist. Depending on the number of items you have you could either manually look through the collection or query directly for an item with this url and depending on the results create the new item with a different url.
Thank you.