PSI Data Export CLI

Command-line tool for exporting ERP data from AFTEC/UniData. Provides both WCF-based and direct database access methods for extracting BOMs, products, and where-used data.


Overview

The PSI Data Export CLI (psi-export.exe) is a .NET command-line tool that exports data from the AFTEC ERP system. It supports multiple export methods with different performance characteristics.

MethodBackendPerformanceUse Case
WCF (bom)PSI Local Service~5-7 min/projectInteractive use, debugging
Direct (direct-bom)UODOTNET (legacy)~6-10 sec/projectBatch exports
Direct + U2 (direct-bom --u2)U2 Toolkit~3-5 sec/projectProduction, fastest

Location: C:\GIT\PSI.All\PSI.DataExport.CLI Output: bin\Release\net48\psi-export.exe


Installation

Build from Source

cd C:\GIT\PSI.All\PSI.DataExport.CLI
 
# Restore packages
"C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\MSBuild.exe" `
  PSI.DataExport.CLI.csproj -t:Restore -p:Configuration=Release
 
# Build
"C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\MSBuild.exe" `
  PSI.DataExport.CLI.csproj -p:Configuration=Release

Note: Must use MSBuild, not dotnet build (PSI libraries have WPF/LC dependencies).

Dependencies

DLLPurposeRequired For
PSI.UniSessionManager.dllUniData session managementLegacy backend
UODOTNET.dllUniData .NET API (deprecated)Legacy backend
U2.Data.Client.dllU2 Toolkit for .NETU2 backend
PSI.DataAccess.dllWCF data accessWCF commands
PSI.Common.dllCommon utilitiesAll
PSI.Common.Models.dllCredential decryptionU2 backend

Commands

bom - BOM Export (WCF)

Export Bill of Materials using the WCF service layer.

# Basic usage
psi-export bom 2356                    # Export BOM for job 2356
 
# Options
psi-export bom 2356 -o output.csv      # Specify output file
psi-export bom 2356 -f json            # Export as JSON
psi-export bom 2356 -t part            # Export for a part number
psi-export bom 2356 -t so              # Export for a sales order
psi-export bom 2356 --no-children      # Top level only

Options:

OptionDescriptionDefault
-o, --outputOutput file pathstdout
-f, --formatOutput format (csv/json)csv
-t, --typeRequest type (job/part/so)job
--flatFlattened outputtrue
-c, --childrenInclude all child levelstrue

direct-bom - Direct Database BOM Export

Export BOM bypassing WCF for significantly faster performance. Uses VB_BOMX.REV1 subroutine directly.

# Single project (legacy UODOTNET backend)
psi-export direct-bom 2356 -o bom_2356.csv
 
# Single project (U2 Toolkit backend - recommended)
psi-export direct-bom 2356 --u2 -o bom_2356.csv
 
# Test mode (check mlevel behavior)
psi-export direct-bom test
psi-export direct-bom 2356              # Test specific project
 
# Batch export (U2 Toolkit recommended for best performance)
psi-export direct-bom -b projects.csv -o BOM_Exports --u2
psi-export direct-bom -b projects.csv -o BOM_Exports --u2 -r  # Resume mode

Options:

OptionDescriptionDefault
-o, --outputOutput file/folder-
-b, --batchBatch mode with CSV input-
-r, --resumeSkip existing exportsfalse
--u2Use U2 Toolkit backend (faster)false

Backend Comparison:

BackendFlagSpeedNotes
UODOTNET (legacy)(default)~700 parts/secDeprecated, uses PSI.UniSessionManager
U2 Toolkit--u2~1300 parts/secModern, recommended for production

Recommendation: Use --u2 for all production workloads. See U2 Toolkit Migration Guide for technical details.

Batch Input Format:

CSV file with ProjectNo column:

ProjectNo,Description
2356,Machine A
2357,Machine B

batch-bom - Parallel BOM Export (WCF)

Export multiple BOMs in parallel using WCF connections.

psi-export batch-bom projects.csv -o BOM_Exports -p 4
psi-export batch-bom projects.csv -o BOM_Exports -r     # Resume

Options:

OptionDescriptionDefault
-o, --outputOutput folderBOM_Exports
-p, --parallelConcurrent exports4
-r, --resumeSkip existingfalse

fast-bom - Fast Parallel Export

Faster batch export with parallel connections and recursive child fetching.

psi-export fast-bom projects.csv -o BOM_Exports -p 6

Options:

OptionDescriptionDefault
-o, --outputOutput folderBOM_Exports
-p, --parallelParallel connections6
-r, --resumeSkip existingfalse

parallel-bom - TRUE Parallel Export

Maximum parallelism using Parallel.ForEach.

psi-export parallel-bom projects.csv -o BOM_Exports -p 8

Options:

OptionDescriptionDefault
-o, --outputOutput folderBOM_Exports
-p, --parallelParallel workers8
-r, --resumeSkip existingfalse

categories - Product Categories

Export product categories from PRODUCT.CLASS.1287.

psi-export categories                  # Export all categories
psi-export categories -c               # Include product counts
psi-export categories -f json          # JSON format
psi-export categories -o cats.csv      # Specify output

Options:

OptionDescriptionDefault
-o, --outputOutput fileauto
-f, --formatFormat (csv/json)csv
-c, --countsInclude countsfalse

products - Product Lookup

Lookup part classification or export all products.

psi-export products 715099             # Lookup single part
psi-export products --all              # Export all products
psi-export products --all -f json      # JSON format

Options:

OptionDescriptionDefault
-o, --outputOutput file-
-f, --formatFormat (csv/json)csv
-a, --allExport all productsfalse

whereused - Where-Used Query

Find all jobs and assemblies that use a part.

psi-export whereused 715099            # Find usage of part
psi-export whereused 715099 -r         # Recursive (all parents)
psi-export whereused -p parts.txt      # Batch from file

Options:

OptionDescriptionDefault
-o, --outputOutput fileauto
-f, --formatFormat (csv/json)csv
-r, --recursiveFind all parent assembliesfalse
-p, --parts-fileBatch input file-

Output Formats

BOM CSV Format

ColumnDescription
LevelHierarchy depth (0 = top)
WbsNumberWork breakdown structure ID
ParentPartNumberParent in hierarchy
PartNumberPart number
DescriptionPart description
GTCodeGroup technology code
QuantityTotal quantity
QtyPerParentQty per parent assembly
QtyPerLegQty in this leg
OnHandInventory on hand
OnOrderQuantity on order
AvailableAvailable quantity
TotalAllocatedTotal allocated
HasChildrenHas child components
IsPurchasedPurchase part flag
IsManufacturedManufactured part flag
JobNumberAssociated job
ExportDateExport timestamp

Where-Used CSV Format

ColumnDescription
QueryPartNumberPart searched for
QueryPartDescriptionPart description
ParentPartNumberParent assembly
ParentDescriptionParent description
ParentGTCodeParent GT code
JobNumberJob using this part
QuantityQuantity used
LevelHierarchy level
WbsNumberWBS ID
ExportDateExport timestamp

Architecture

WCF Flow (Slow)

CLI → PSI.DataAccess → WCF Service → PSI Local Service
    → UniData Subroutine → AFTEC Database

Each BOM level requires a separate WCF call with 100-500ms overhead. A project with 2,000 parts needs 100-200+ sequential calls.

Direct Database Flow (Fast)

Two backend options for direct database access:

Legacy Backend (UODOTNET)

CLI → PSI.UniSessionManager → UDSessionController → UODOTNET.dll
    → VB_BOMX.REV1 → AFTEC Database
  • Uses deprecated UODOTNET.dll via PSI.UniSessionManager
  • ~700 parts/second throughput
  • Default behavior (no flag needed)
CLI → U2.Data.Client.dll → UniSession → CreateUniSubroutine()
    → VB_BOMX.REV1 → AFTEC Database
  • Uses modern U2.Data.Client.dll directly
  • ~1300 parts/second throughput (~2x faster)
  • Enable with --u2 flag
  • Officially supported by Rocket Software

See U2 Toolkit Migration Guide for implementation details.

Key Subroutine: VB_BOMX.REV1

Both backends use VB_BOMX.REV1 for BOM explosion:

Parameters:

  1. Company (always “1”)
  2. ReqType (“JOB” or “PART”)
  3. IncludeParts (“1”)
  4. MLevel (“0” - handled in code)
  5. LDS (“0”)
  6. PartNumber (job or part number)
  7. Qty (“1”)
  8. WBS (work breakdown structure)
  9. RawData (output)
  10. MessageInfo (output)

Returns immediate children only; the CLI recursively fetches all levels.


Performance Comparison

MethodBackendTime/Project100 ProjectsParts/sec
bom (WCF)WCF Service~5-7 min~10 hours~5
batch-bom (4x parallel)WCF Service~5-7 min~2.5 hours~20
direct-bomUODOTNET~6-10 sec~15 min~700
direct-bom --u2U2 Toolkit~3-5 sec~8 min~1300

Recommendation: Use direct-bom --u2 for all batch exports.


Common Use Cases

Export All Project BOMs (Fastest)

# Create project list from recent projects
# (assumes you have a CSV with ProjectNo column)
 
# Fast batch export with U2 Toolkit and resume capability
psi-export direct-bom -b shipped_projects.csv -o BOM_Exports --u2 -r

Lookup Part Usage

# Find all jobs using a specific part
psi-export whereused 715099 -r -o whereused_715099.csv

Export Product Classifications

# Export all products with their categories
psi-export products --all -o products_with_class.csv

Troubleshooting

”Failed to establish database session”

  • Ensure you’re logged into Windows with a valid PSI account
  • Check that PSI Local Service is running (for WCF commands)
  • Verify UniData connectivity

”The user name or password provided is incorrect” (Error 80011)

When using --u2 flag:

”User/pool limit reached” (Error 39134)

When using --u2 flag:

  • Connection pooling requires specific server license
  • The CLI disables pooling by default to avoid this
  • If you see this error, ensure Pooling = false in connection string

”No BOM data returned”

  • Verify the job/project number exists
  • Check if the project has a released BOM
  • Try the WCF bom command to compare results

Slow Performance

  • Use direct-bom --u2 instead of bom for batch operations
  • Check network connectivity to UniData server
  • Consider running during off-peak hours

Source Files

Key implementation files in PSI.DataExport.CLI:

FilePurpose
Commands/DirectBomCommand.csCLI command handler
Services/DirectBomExporter.csLegacy UODOTNET implementation
Services/U2ToolkitBomExporter.csU2 Toolkit implementation
Helpers/UniDynArrayParser.csParses U2 Toolkit results

Future Commands

Planned additions based on available UniData subroutines:

CommandPriorityDescription
direct-partsHighPart master export
direct-jobsHighWork order data
direct-inventoryMediumInventory levels
xrefLowPart cross-reference


Last updated: February 2025