# Connecting Autodesk & ERP

ERP systems that provide an OData interface can be directly connected to applications such as Vault Client, Inventor or AutoCAD.
But also ERP systems which doesn’t expose a web API can be connected using powerGateServer, who then acts as a middleman and translator.

## ERP integrations

Vault Clients and CAD applications can be easily connected to ERP systems using the powerGate Cmdlets or the .NET library.
Depending on whether data synchronizations must be fully automated, partially automated or performed manually, an ERP integration can be realized using powerJobs Processor, powerEvents and Autodesk Vault Data Standard.

### Scripts

Some PowerShell scripts are delivered with the product, all starting with the name ‘Sample.’. Their purpose is mainly to help getting started with implementing an ERP integration based on powerEvents.

The following sample scripts are installed to %ProgramData%\coolOrange\powerEvents\Events:

These samples cover the most common scenarios for connecting and exchanging data between Vault and an ERP system.

When starting Vault applications and logging into Vault, the Sample.ConnectToPowerGateServer script automatically connects to powerGateServer.

Afterwards, an “ERP Item” tab and an “ERP BOM” tab are displayed in the Vault Client for selected files and items.
For files, the Sample.TransferERPItemViaFileTab script displays the information of the corresponding ERP Item and the Sample.TransferERPBOMViaFileTab script displays the current bill of materials from the ERP system.
For selected Vault items, the scripts Sample.TransferERPItemViaItemTab and Sample.TransferERPBOMViaItemTab create the corresponding ERP tabs in the Vault Client.
All the tabs are delivered with corresponding .xaml files (Extensible Application Markup Language) which are used by both “ERP Item” and “ERP BOM” tabs.
These describe the layout, including the controls used (label, text field, combo box, etc.).

Customizations

For all sample scripts and the according xaml files it is recommended to create a copy when they need to be customized.
Disable the used sample script by simply moving it to the %PROGRAMDATA%\coolOrange\powerEvents\Events\Disabled directory.

### Modules

The powerGate_Connections.psm1 module is delivered in the Cmdlets installation directory %ProgramFiles%\coolOrange\Modules\powerGate.
It gets automatically imported with the powerGate module and provides a global $sapConnect variable for connecting to SAP systems. The$global:Host.PrivateData.OnNonTerminatingError extension ensures that Vault users are notified about connection problems and can better understand whether the problem is caused by their client-machine, by powerGateServer or directly triggered by the ERP system.

## Errors

Powershell hosting applications inform scripting guys and Vault users in different ways about Terminating Errors that arise during script or module executions :

• powerEvents displays Error Message Boxes

• The BOM Window displays Error Dialogs during Check- and Transfer operations or failure Icons while loading the BOM tree

• powerJobs Processor jobs fail

• Autodesk Vault Data Standard writes to the Log File and shows Message Boxes in several customization areas

• PowerShell IDE’s display the error message and its stack trace with red text in the terminal when the script execution stops

Instead, when Non-Terminating Errors occur within Cmdlets, the script execution is not stopped by default (see -ErrorAction:Continue parameter) and further information is available in the global $Error variable. For connection problems, these would be the WebRequestException details provided by ERP cmdlets. By default, Vault users are informed about connection troubles in all types of ERP integrations using the powerGate_Connections.psm1 module. In applications such as the Vault Client, Inventor or AutoCAD a Connection Error Dialog will be displayed, which helps to understand whether the connection problem was caused by the client-machine (no request was send), the powerGateServer or directly by the ERP system (error response): All other types of Non-Terminating Errors are displayed using an Error Message Box which helps to identify incorrectly used ERP cmdlets or problematic parameters: BOM Window - Non-Terminating Errors Such modal error dialogs are not displayed during the BOM Window Check- and Transfer functions where problems with ERP cmdlets occur. Instead, the current processed$bom, $bomRow and$item objects are automatically assigned with an Error Status:

The automatically set _StatusDetails help the Vault user to localize the cause of connection problems more precisely.
Unfortunately the operations are not automatically terminated after problematic ERP cmdlet usages or incorrect parameter values, but also in this case additional stack trace information allows the scripting guy to find the problematic line faster.

Vault Restriction events - Non-Terminating Errors

All Vault Restriction events that encounter ERP cmdlet errors are automatically restricted to prevent the configured process from passing successfully even though connection or cmdlet problems have occurred:

Unfortunately, the executed Restrictions event actions are not automatically aborted directly after problematic ERP cmdlet usages or incorrect parameter values.
Still, additional stack trace information helps the script guy to quickly find and correct the affected ERP cmdlet line.

In any case, all error details are logged and can be found in the logfile.