Try our conversational search powered by Generative AI!

Default values when copy

Vote:
 

When a new product is created in our catalog we override the default product code suggested by episerver from the SetDefaultValue function. However, this function is not called when a product is duplicated and we want to suggest

Are there any way to default values when duplicating?

#142801
Dec 28, 2015 16:06
Vote:
 

When copying, the values that were set by SetDefaultValues on the original page are in the copied content item right? Which is what I would expect. SetDefaultValues only gets called when creating a new content item as far as I know.

You could attach some functionality to the CreatedContent or CreatingContent event. Set the values there?

Don't forget to check, in your case, if the item is copied

if (contentEventArgs.GetType() == typeof(CopyContentEventArgs))
            {
                
            }
#142803
Dec 29, 2015 12:00
Vote:
 

The method which Stemerdink suggested for detecting a product duplication works perfectly but I gave me some other issues.

The Content property on the contentEventArgs was NULL so I had to Get the content using the ContentRepository and the ContentLink. This was only possible at CreatedContent event (At the CreatingContent event both content and content link was NULL).

Now that I have the content, I tried to chance the product Code by assigning a new value to the property. This throws an exception stating that Code is read only. Anyone know how to change the product code programmably?

#142911
Jan 05, 2016 14:18
Vote:
 

You can't change it when you create a WriteableClone?

Don't forget to save it again, probably you should force the current version when saving, else you get an extra version

#142912
Jan 05, 2016 14:30
Vote:
 

If i create a writeableclone it's possible to update the code. I saved the clone with 

var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();
contentRepository.Save(content, SaveAction.Publish, AccessLevel.NoAccess);

Thanks! 

#142932
Jan 06, 2016 13:43
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.