export
Before you can import, you need to know how to export.
You can export workflows with something like this:
You need to use Export-OpenRPAWorkflow to ensure all images get embedded into the activities. This way, when you open the workflow in OpenRPA, it can extract and save it as a file inside OpenFlow again.
import
So once you have your workflows, you can loop over the JSON files and import them using Set-Entity.
UNTESTED I don’t have something to test on right now, so I asked ChatGPT to write something, and at a glance, this looks correct to me.
# Set the path where the exported workflows are stored
$exportedWorkflowsPath = "C:\Path\To\ExportedWorkflows"
# Loop through each project folder
foreach ($projectFolder in Get-ChildItem -Path $exportedWorkflowsPath -Directory) {
$projectName = $projectFolder.Name
# Optionally, find the matching project entity or create one if it doesn't exist
$projectEntity = Get-Entity -Collection openrpa -Query "{`"_type`":`"project`", `"name`":`"$projectName`"}"
if (-not $projectEntity) {
Write-Host "Project '$projectName' does not exist, creating it..."
$projectEntity = @{
_type = "project"
name = $projectName
} | Set-Entity -Collection openrpa
}
# Get the project ID
$projectId = $projectEntity._id
# Loop through each workflow file in the project folder
foreach ($workflowFile in Get-ChildItem -Path $projectFolder.FullName -Filter "*.json") {
# Read the workflow content
$workflowContent = Get-Content -Path $workflowFile.FullName -Raw | ConvertFrom-Json
# Update the project ID and type in the workflow content
$workflowContent._type = "workflow"
$workflowContent.projectid = $projectId
# Import the workflow using Set-Entity
$workflowContent | Set-Entity -Collection openrpa -Force
Write-Host "Imported workflow: $($workflowContent.name) into project: $projectName"
}
}