Search code examples
sitefinity

What is the proper method to programmatically create a copy of a sitefinity (custom module) contents?


We are using Sitefinity 9.2. We have created custom module for content storage. All our custom modules have fields like Customer, category and instructions. We want to have a feature to easily copy the instructions of an existing Customer and to create the same instructions for new customer.

We need something like this:

Instructions = Find customer X instructions(); 
for each item in Instructions {
    Create content for new customer();
}

How we can implement this within Sitefinity itself? Can we create a custom UI, where we can search for the instructions based on Customer Id and then can create a copy of those instructions for new customer?


Solution

  • I assume you created the custom module by using the Dynamic Module Builder. If so, it provides an API for CRUD operations on items.

    So yes, you can create a custom widget and put it on a custom backend page, that can provide a list of existing customers, allow the user to select one (source) and create a new one (target) by copying all (or some) of the properties of the source.

    More general documentation: https://docs.sitefinity.com/for-developers-dynamic-modules

    You've probably already noticed, but in the top right corner of your dynamic module's definition page (/Sitefinity/Administration/Module-builder/module/type/MODULETYPE_GUID) there is a link that says "Code reference for XXX module" - that will provide more API examples for your particular module.