@vltech/nocobase-plugin-workflow-duplicate-record
v0.1.0
Published
A NocoBase workflow plugin that adds a **Duplicate Record** node to your workflow builder. This allows you to easily create copies of existing records with the ability to customize specific fields in the duplicated record.
Readme
@vltech/nocobase-plugin-workflow-duplicate-record
A NocoBase workflow plugin that adds a Duplicate Record node to your workflow builder. This allows you to easily create copies of existing records with the ability to customize specific fields in the duplicated record.
What Does This Plugin Do?
This plugin adds a new workflow node called "Duplicate Record" that you can use in your NocoBase workflows. When triggered, it will:
- Find an existing record in any collection
- Create a copy of that record with all its data
- Optionally customize specific fields in the new copy
- Return the newly created record for use in subsequent workflow steps
Perfect for scenarios like:
- Creating template-based records (duplicate a template and customize it)
- Copying orders, products, or documents with modified fields
- Archiving records by creating duplicates with different status
- Building approval workflows where you need modified copies
Installation
Step 1: Install the Plugin
Add the plugin to your NocoBase installation:
yarn add @vltech/nocobase-plugin-workflow-duplicate-recordStep 2: Enable the Plugin
- Log in to your NocoBase admin panel
- Go to Settings → Plugin Manager
- Find "Workflow: Duplicate Record" in the plugin list
- Click Enable to activate the plugin
Once enabled, the "Duplicate Record" node will be available in all your workflow builders.
How to Use in NocoBase UI
Adding the Duplicate Record Node to a Workflow
- Open or create a workflow in NocoBase (Settings → Workflow)
- Click the + button to add a new node
- Select "Duplicate Record" from the instruction list
- Configure the node using the settings panel (see below)
Configuring the Node
The Duplicate Record node has the following configuration options:
1. Collection (Required)
Select the collection that contains the record you want to duplicate.
- In the UI: Use the dropdown to select from your available collections
- Example: Select "Products" to duplicate a product record
2. Source Record ID (Optional*)
Specify which record to duplicate.
- Option A - Use a specific ID: Enter or select a record ID directly
- Option B - Use workflow variable: Click the "x" button next to the field to use variables from previous workflow nodes
- Option C - Use previous node result: Leave empty to automatically use the record from the previous workflow node
*If you leave this empty, the plugin will automatically use the id from the previous workflow node's result.
3. Field Overrides (Optional)
Customize specific fields in the duplicated record.
- Click "Add field override" to add a new override
- Field: Select which field you want to customize
- Value: Enter the new value (can use workflow variables)
Common examples:
- Change the "Status" field to "Draft"
- Modify the "Name" field to add "Copy of..." prefix
- Update date fields to current date
- Change ownership or assignment fields
4. Continue on Failure (Optional)
Toggle this option to control what happens if duplication fails.
- Off (default): Workflow stops if duplication fails
- On: Workflow continues even if duplication fails (useful for non-critical duplications)
Example Use Cases
Example 1: Duplicate a Product as a Draft
Scenario: You want to duplicate an existing product but set its status to "Draft" for editing.
Configuration:
- Collection: Products
- Source Record ID: Use workflow variable or enter product ID
- Field Overrides:
- Field: "status" → Value: "draft"
- Field: "name" → Value:
{{$context.name}} (Copy)
Example 2: Create Order Copy for Archive
Scenario: When an order is completed, create a copy for archival purposes.
Configuration:
- Collection: Orders
- Source Record ID: Leave empty (uses trigger record)
- Field Overrides:
- Field: "status" → Value: "archived"
- Field: "archivedDate" → Value:
{{$system.now}}
Example 3: Template-Based Record Creation
Scenario: Use a template record to create new records with specific customizations.
Configuration:
- Collection: Projects
- Source Record ID: 123 (your template project ID)
- Field Overrides:
- Field: "name" → Value:
{{$context.clientName}} Project - Field: "startDate" → Value:
{{$system.now}} - Field: "status" → Value: "planning"
- Field: "name" → Value:
How It Works
Field Copying: The plugin copies all regular fields from the source record, excluding:
- System fields:
id,createdAt,updatedAt,createdById,updatedById,createdBy,updatedBy,__v,sort - Relation fields themselves (but their foreign keys are copied)
- System fields:
Relation Handling:
- BelongsTo relations: Foreign keys are automatically copied as regular fields
- HasOne, HasMany, BelongsToMany: Not duplicated (only applicable to the original record)
Field Overrides: Applied after copying, allowing you to customize specific fields in the new record
Result: Returns the newly created record as JSON, which can be used in subsequent workflow nodes
Output
The instruction returns a job result with the following structure:
{
status: 'resolved' | 'failed',
result: {
// The duplicated record data (if successful)
id: number,
// ... all other fields from the duplicated record
// Or error information (if failed)
error: string,
stack: string
}
}Development
See the root README for development setup instructions.
License
See the root package.json for license information.
