Skip to content

Commit

Permalink
Feature fieldmapping readme (PSv2) (#12)
Browse files Browse the repository at this point in the history
* Fix: moved throw to try/catch

* Fix: throw to try/catch and throw when aref empty

* Feat: added verbose message for update on update

* Feat: add fieldMapping and updated readme

* Feat: added example how to update custom field

* Feat: added forum post in readme

* Fix: removed mapping folder

* Fix: Update Logo URL

* Fix: Now correctly explain custom field mapping

* fix: updateOnupdate to onlyUpdateOnCorrelate

* fix: user to employee

* fix: onlyUpdateOnCorrelate toggle was flipped

---------

Co-authored-by: Rick Jongbloed <r.jongbloed@tools4ever.com>
  • Loading branch information
rhouthuijzen and Rick-Jongbloed committed Jun 24, 2024
1 parent f2ce5f9 commit 6d8a7ae
Show file tree
Hide file tree
Showing 7 changed files with 342 additions and 189 deletions.
11 changes: 0 additions & 11 deletions Mapping/EmAd.js

This file was deleted.

250 changes: 168 additions & 82 deletions README.md

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@
}
},
{
"key": "updateOnUpdate",
"key": "onlyUpdateOnCorrelate",
"type": "checkbox",
"defaultValue": false,
"templateOptions": {
"label": "Update on update",
"label": "Only update on correlate",
"required": false,
"description": "When toggled, if the mapped data differs from data in AFAS, the AFAS user will be updated when a update is triggerd"
"description": "When toggled, the AFAS employee will only be updated when the account is correlated"
}
},
{
Expand All @@ -61,4 +61,4 @@
"required": false
}
}
]
]
47 changes: 23 additions & 24 deletions create.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#####################################################
# HelloID-Conn-Prov-Target-AFAS-Profit-Employees-Create
#
# Version: 3.0.0 | new-powershell-connector
# PowerShell V2
#####################################################

# Set to true at start, because only when an error occurs it is set to false
Expand All @@ -19,28 +18,6 @@ switch ($($actionContext.Configuration.isDebug)) {
# Enable TLS1.2
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor [System.Net.SecurityProtocolType]::Tls12

if ($actionContext.CorrelationConfiguration.Enabled) {
$correlationProperty = $actionContext.CorrelationConfiguration.accountField
$correlationValue = $actionContext.CorrelationConfiguration.accountFieldValue

if ([string]::IsNullOrEmpty($correlationProperty)) {
Write-Warning "Correlation is enabled but not configured correctly."
Throw "Correlation is enabled but not configured correctly."
}

if ([string]::IsNullOrEmpty($correlationValue)) {
Write-Warning "The correlation value for [$correlationProperty] is empty. This is likely a scripting issue."
Throw "The correlation value for [$correlationProperty] is empty. This is likely a scripting issue."
}
}
else {
$outputContext.AuditLogs.Add([PSCustomObject]@{
Message = "Configuration of correlation is mandatory."
IsError = $true
})
Throw "Configuration of correlation is mandatory."
}

#region functions
function Resolve-HTTPError {
[CmdletBinding()]
Expand Down Expand Up @@ -137,6 +114,28 @@ function Get-ErrorMessage {

# Get current account and verify if there are changes
try {
if ($actionContext.CorrelationConfiguration.Enabled) {
$correlationProperty = $actionContext.CorrelationConfiguration.accountField
$correlationValue = $actionContext.CorrelationConfiguration.accountFieldValue

if ([string]::IsNullOrEmpty($correlationProperty)) {
Write-Warning "Correlation is enabled but not configured correctly."
Throw "Correlation is enabled but not configured correctly."
}

if ([string]::IsNullOrEmpty($correlationValue)) {
Write-Warning "The correlation value for [$correlationProperty] is empty. This is likely a scripting issue."
Throw "The correlation value for [$correlationProperty] is empty. This is likely a scripting issue."
}
}
else {
$outputContext.AuditLogs.Add([PSCustomObject]@{
Message = "Configuration of correlation is madatory."
IsError = $true
})
Throw "Configuration of correlation is madatory."
}

Write-Verbose "Querying AFAS employee where [$($correlationProperty)] = [$($correlationValue)]"

# Create authorization headers
Expand Down
72 changes: 39 additions & 33 deletions delete.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#####################################################
# HelloID-Conn-Prov-Target-AFAS-Profit-Employees-Delete
#
# Version: 3.0.0 | new-powershell-connector
# PowerShell V2
#####################################################

# Set to true at start, because only when an error occurs it is set to false
Expand All @@ -16,35 +15,6 @@ switch ($($actionContext.Configuration.isDebug)) {
# Enable TLS1.2
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor [System.Net.SecurityProtocolType]::Tls12

$account = $actionContext.Data

$correlationProperty = $actionContext.CorrelationConfiguration.accountField
$correlationValue = $actionContext.References.Account.Medewerker # Has to match the AFAS value of the specified filter field ($filterfieldid)

if ([string]::IsNullOrEmpty($correlationProperty)) {
Write-Warning "Correlation is enabled but not configured correctly."
Throw "Correlation is enabled but not configured correctly."
}

if ([string]::IsNullOrEmpty($correlationValue)) {
Write-Warning "The correlation value for [$correlationProperty] is empty. Account Refference is empty."
Throw "The correlation value for [$correlationProperty] is empty. Account Refference is empty."
}

$updateAccountFields = @()
if ($account.PSObject.Properties.Name -Contains 'EmAd') {
$updateAccountFields += "EmAd"
}
if ($account.PSObject.Properties.Name -Contains 'EmailPortal') {
$updateAccountFields += "EmailPortal"
}
if ($account.PSObject.Properties.Name -Contains 'TeNr') {
$updateAccountFields += "TeNr"
}
if ($account.PSObject.Properties.Name -Contains 'MbNr') {
$updateAccountFields += "MbNr"
}

#region functions
function Resolve-HTTPError {
[CmdletBinding()]
Expand Down Expand Up @@ -141,6 +111,37 @@ function Get-ErrorMessage {

# Get current account and verify if there are changes
try {
$account = $actionContext.Data

$correlationProperty = $actionContext.CorrelationConfiguration.accountField
$correlationValue = $actionContext.References.Account.Medewerker # Has to match the AFAS value of the specified filter field ($filterfieldid)

$updateAccountFields = @()
if ($account.PSObject.Properties.Name -Contains 'EmAd') {
$updateAccountFields += "EmAd"
}
if ($account.PSObject.Properties.Name -Contains 'EmailPortal') {
$updateAccountFields += "EmailPortal"
}
if ($account.PSObject.Properties.Name -Contains 'TeNr') {
$updateAccountFields += "TeNr"
}
if ($account.PSObject.Properties.Name -Contains 'MbNr') {
$updateAccountFields += "MbNr"
}

# Verify if [aRef] has a value
if ([string]::IsNullOrEmpty($($actionContext.References.Account))) {
$outputContext.AuditLogs.Add([PSCustomObject]@{
Action = "UpdateAccount"
Message = "The account reference could not be found"
IsError = $true
})

throw 'The account reference could not be found'
}


try {
Write-Verbose "Querying AFAS employee where [$($correlationProperty)] = [$($correlationValue)]"

Expand Down Expand Up @@ -218,7 +219,7 @@ try {
}

# Skip further actions, as this is a critical error
continue
throw "Error querying AFAS employee"
}

switch ($updateAction) {
Expand Down Expand Up @@ -310,8 +311,9 @@ try {
Message = "Error updating AFAS employee [$($currentAccount.Medewerker)]. Error Message: $($errorMessage.AuditErrorMessage). Old values: $($changedPropertiesObject.oldValues | ConvertTo-Json -Depth 10). New values: $($changedPropertiesObject.newValues | ConvertTo-Json -Depth 10)"
IsError = $true
})
# Skip further actions, as this is a critical error
throw "Error updating AFAS employee"
}

break
}
'NoChanges' {
Expand All @@ -338,6 +340,10 @@ try {
}
}
}
catch {
$ex = $PSItem
Write-Verbose "ERROR: $ex"
}
finally {
# Check if auditLogs contains errors, if errors are found, set succes to false
if ($outputContext.AuditLogs.IsError -contains $true) {
Expand Down
66 changes: 66 additions & 0 deletions fieldMapping.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"Version": "v1",
"MappingFields": [
{
"Name": "Medewerker",
"Description": "[Mandatory]",
"Type": "Text",
"MappingActions": [
{
"MapForActions": [
"Create",
"Update"
],
"MappingMode": "Field",
"Value": "\"Person.ExternalId\"",
"UsedInNotifications": false,
"StoreInAccountData": true
}
]
},
{
"Name": "Persoonsnummer",
"Description": "[Mandatory]",
"Type": "Text",
"MappingActions": [
{
"MapForActions": [
"Create",
"Update"
],
"MappingMode": "None",
"Value": "\"\"",
"UsedInNotifications": false,
"StoreInAccountData": true
}
]
},
{
"Name": "EmAd",
"Description": "",
"Type": "Text",
"MappingActions": [
{
"MapForActions": [
"Create",
"Update"
],
"MappingMode": "Complex",
"Value": "\"function getEmail() {\\r\\n let mail = '';\\r\\n\\r\\n if (typeof Person.Accounts.MicrosoftActiveDirectory.mail !== 'undefined' && Person.Accounts.MicrosoftActiveDirectory.mail) {\\r\\n mail = Person.Accounts.MicrosoftActiveDirectory.mail;\\r\\n }\\r\\n\\r\\n return mail;\\r\\n}\\r\\n\\r\\ngetEmail()\"",
"UsedInNotifications": false,
"StoreInAccountData": true
},
{
"MapForActions": [
"Delete"
],
"MappingMode": "Fixed",
"Value": "\"\"",
"UsedInNotifications": false,
"StoreInAccountData": false
}
]
}
],
"UniqueFieldNames": []
}
Loading

0 comments on commit 6d8a7ae

Please sign in to comment.