Settings

The ERPSettings object allows reading and writing the configuration from the C:\ProgramData\coolOrange\powerGate.settings file.
This settings file corresponds to the Vault file located at $/powerGate.settings (see Settings File).

Changing Settings

Since these settings apply to the entire Vault ERP Integrations for all Vault users, the settings should be changed by Vault administrators using the Settings Dialog (Editor object).

In exceptional cases the C:\ProgramData\coolOrange\powerGate.settings file can be edited in external tools and then checked back into Vault. This is useful when working in multiple Vaults with slightly different settings.
The Vault History tab can be used to track changes and also to revert to working versions in case of configuration problems.

Syntax

$ERPSettings

The following properties are available in addition to the derived ApplicationSettingsBase type:

Type

Name

Description

System.Collections.Generic.List<ServiceSettings>

Services

Provides the settings for all configured OData services used to establish the connection to ERP (e.g. the Service URLs).
For connections routed through the powerGateServer, other additional settings are possible than e.g. for SAP Gateway services.

System.Collections.Generic.List<VaultToERPMappings>

TypeMappings

Grants access to mapping configurations between Vault entity types and ERP entity types.
This includes details such as where each ERP Field’s data comes from (e.g. from a VaultProperty or fixed-value).

Window

Editor

ERP Integration Settings dialog for displaying and changing the configuration Vault-wide.

In addition, ApplicationSettingsBase also provides methods for reading and writing to the powergate.settings file (e.g. Reload(), Reset() and Save()).

Examples

Retrieving all configured Services for connecting the ERP system:

$global:ERPSettings.Services | Format-List -Property *,@{'Label'='Type'; 'Expression'={$_.GetType().Name}}

<#
Service          : http://MyADMS:8080/PGS/my_company/ErpService
Host             :
Port             :
ServicePath      :
IsDefaultSetting : False
Type             : PowerGateServerServiceSettings

Service          : http://sap.coolorange.com/sap/opu/odata/arcona6/DOCUMENT_INFO_RECORD_SRV
IsDefaultSetting : False
Type             : ServiceSettings
#>

Extending ERP field mapping configurations for complex and calculated PowerShell values:

$vaultFile2ErpItemSettings = $global:ERPSettings.GetTypeMapping('File', 'Item')
$descriptionFieldSettings = $vaultFile2ErpItemSettings.FieldMappingsForCreate | Where-Object { $_.ErpField -eq 'Description' }
$descriptionFieldSettings.ConvertToErpValue = {
        param($vaultFile)

        $entireDescription = $vaultFile._Description.Trim([Char]'.') # remove dots at the beginning and end
        if($vaultFile.Description_2) {
            $entireDescription += ' - '
            $entireDescription += $vaultFile.Description_2.Substring(0,17)
        }

        foreach($invalidCharacter in  @('<', '>', ':', '*', '/', '\')) {
            if($entireDescription.Contains($invalidCharacter)) {
                throw "The translation of the Vault descriptions failed because the resulting ERP description can not contain the character '$invalidCharacter'"
            }
        }
        return $entireDescription
    }
}

$global:ERPSettings.GetTypeMapping('FileBomRow', 'BomRow'). `
    FieldMappingsForCreate = (
        [powerGate.Erp.Client.Properties.FieldSettings] @{

            ERPField = 'ChildNumber'
            ConvertToErpValue = {
                param($vaultBomRow)

                if(-not $vaultBomRow._PartNumber) {
                    return $vaultBomRow.'Raw Material Number'
                }
                return $vaultBomRow._PartNumber
            }
        },
        [powerGate.Erp.Client.Properties.FieldSettings] @{

            ERPField = 'ParentNumber'
            ConvertToErpValue = { param($vaultBomRow) $vaultBOM._PartNumber.ToUpper() }
        }
    )


$global:ERPSettings.TypeMappings | Select-Object -Property *, @{'Label'='FieldMappingsForCreate'; 'Expression'={ '[{0}]' -f ($_.FieldMappingsForCreate | format-list | Out-String) }} -ExcludeProperty 'FieldMappingsForCreate' `
    | Format-List

<#
VaultEntityType        : File
ErpEntityType          : ErpServices.Services.Entities.Item
FieldMappingsForCreate : [
                            ErpField          : Number
                            VaultProperty     : File Name
                            DefaultValue      : 
                            ConvertToErpValue : System.Func`2[System.Object,System.Object]
                            
                            ErpField          : Description
                            VaultProperty     : 
                            DefaultValue      : 
                            ConvertToErpValue : { param($vaultFile) ... }
                         ]
IsDefaultSetting       : False

VaultEntityType        : FileBomRow
ErpEntityType          : ErpServices.Services.Entities.BomRow
FieldMappingsForCreate : [
                            ErpField          : ChildNumber
                            VaultProperty     : 
                            DefaultValue      : 
                            ConvertToErpValue : { param($vaultBomRow) ... }

                            ErpField          : ParentNumber
                            VaultProperty     : 
                            DefaultValue      : 
                            ConvertToErpValue : { param($vaultBomRow) $vaultBOM._PartNumber.ToUpper() }
                         ]
IsDefaultSetting       : False
#>


Retrieve values for drop-down lists live from ERP and cache them for performance reasons:

This example also helps to quickly create an initial configuration with all possible ERP values, especially if the allowed ERP keys are unknown and have to be queried via API.
Then, the actual list-values to be used can easily be further adapted and saved by the Vault administrator via the Settings Dialog.

# e.g. directly after line: Connect-ERP -UseSettingsFromVault

$matlGroupFieldSettings = $global:ERPSettings.GetTypeMapping('File', 'BasicData'). `
    FieldMappingsForCreate | Where-Object { $_.ErpField -eq 'MatlGroup' }

if(-not $matlGroupFieldSettings.ListValues) {
    $allSapMaterialGroups = Get-ERPObjects -EntitySet 'MatlGroupLookupCollection'

    foreach ($sapMaterialGroup in $allSapMaterialGroups) {
        $matlGroupFieldSettings.ListValues.Add( (New-Object powerGate.Erp.Client.Properties.ListValueEntry -Property @{
            Erp     = $sapMaterialGroup.MatlType
            Display = $sapMaterialGroup.Description
        }) )
    }
    $matlGroupFieldSettings.DefaultValue = $allSapMaterialGroups[0].MatlType
}

$matlGroupFieldSettings | Format-List
<#
ErpField          : MatlGroup
VaultProperty     : 
DefaultValue      : 06
ListValues        : [
                        Display : Oil Products
                        Erp     : 06
                        Vault   : 

                        Display : SSR-Gasoline Prods
                        Erp     : 02
                        Vault   : 

                        Display : Material group 2
                        Erp     : 03
                        Vault   : 

                        ...
                    ]
ConvertToErpValue : System.Func`2[System.Object,System.Object]
#>