Skip to content

Commit 6d8a7ae

Browse files
Feature fieldmapping readme (PSv2) (#12)
* 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 <[email protected]>
1 parent f2ce5f9 commit 6d8a7ae

File tree

7 files changed

+342
-189
lines changed

7 files changed

+342
-189
lines changed

Mapping/EmAd.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

README.md

Lines changed: 168 additions & 82 deletions
Large diffs are not rendered by default.

configuration.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@
4242
}
4343
},
4444
{
45-
"key": "updateOnUpdate",
45+
"key": "onlyUpdateOnCorrelate",
4646
"type": "checkbox",
4747
"defaultValue": false,
4848
"templateOptions": {
49-
"label": "Update on update",
49+
"label": "Only update on correlate",
5050
"required": false,
51-
"description": "When toggled, if the mapped data differs from data in AFAS, the AFAS user will be updated when a update is triggerd"
51+
"description": "When toggled, the AFAS employee will only be updated when the account is correlated"
5252
}
5353
},
5454
{
@@ -61,4 +61,4 @@
6161
"required": false
6262
}
6363
}
64-
]
64+
]

create.ps1

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#####################################################
22
# HelloID-Conn-Prov-Target-AFAS-Profit-Employees-Create
3-
#
4-
# Version: 3.0.0 | new-powershell-connector
3+
# PowerShell V2
54
#####################################################
65

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

22-
if ($actionContext.CorrelationConfiguration.Enabled) {
23-
$correlationProperty = $actionContext.CorrelationConfiguration.accountField
24-
$correlationValue = $actionContext.CorrelationConfiguration.accountFieldValue
25-
26-
if ([string]::IsNullOrEmpty($correlationProperty)) {
27-
Write-Warning "Correlation is enabled but not configured correctly."
28-
Throw "Correlation is enabled but not configured correctly."
29-
}
30-
31-
if ([string]::IsNullOrEmpty($correlationValue)) {
32-
Write-Warning "The correlation value for [$correlationProperty] is empty. This is likely a scripting issue."
33-
Throw "The correlation value for [$correlationProperty] is empty. This is likely a scripting issue."
34-
}
35-
}
36-
else {
37-
$outputContext.AuditLogs.Add([PSCustomObject]@{
38-
Message = "Configuration of correlation is mandatory."
39-
IsError = $true
40-
})
41-
Throw "Configuration of correlation is mandatory."
42-
}
43-
4421
#region functions
4522
function Resolve-HTTPError {
4623
[CmdletBinding()]
@@ -137,6 +114,28 @@ function Get-ErrorMessage {
137114

138115
# Get current account and verify if there are changes
139116
try {
117+
if ($actionContext.CorrelationConfiguration.Enabled) {
118+
$correlationProperty = $actionContext.CorrelationConfiguration.accountField
119+
$correlationValue = $actionContext.CorrelationConfiguration.accountFieldValue
120+
121+
if ([string]::IsNullOrEmpty($correlationProperty)) {
122+
Write-Warning "Correlation is enabled but not configured correctly."
123+
Throw "Correlation is enabled but not configured correctly."
124+
}
125+
126+
if ([string]::IsNullOrEmpty($correlationValue)) {
127+
Write-Warning "The correlation value for [$correlationProperty] is empty. This is likely a scripting issue."
128+
Throw "The correlation value for [$correlationProperty] is empty. This is likely a scripting issue."
129+
}
130+
}
131+
else {
132+
$outputContext.AuditLogs.Add([PSCustomObject]@{
133+
Message = "Configuration of correlation is madatory."
134+
IsError = $true
135+
})
136+
Throw "Configuration of correlation is madatory."
137+
}
138+
140139
Write-Verbose "Querying AFAS employee where [$($correlationProperty)] = [$($correlationValue)]"
141140

142141
# Create authorization headers

delete.ps1

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#####################################################
22
# HelloID-Conn-Prov-Target-AFAS-Profit-Employees-Delete
3-
#
4-
# Version: 3.0.0 | new-powershell-connector
3+
# PowerShell V2
54
#####################################################
65

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

19-
$account = $actionContext.Data
20-
21-
$correlationProperty = $actionContext.CorrelationConfiguration.accountField
22-
$correlationValue = $actionContext.References.Account.Medewerker # Has to match the AFAS value of the specified filter field ($filterfieldid)
23-
24-
if ([string]::IsNullOrEmpty($correlationProperty)) {
25-
Write-Warning "Correlation is enabled but not configured correctly."
26-
Throw "Correlation is enabled but not configured correctly."
27-
}
28-
29-
if ([string]::IsNullOrEmpty($correlationValue)) {
30-
Write-Warning "The correlation value for [$correlationProperty] is empty. Account Refference is empty."
31-
Throw "The correlation value for [$correlationProperty] is empty. Account Refference is empty."
32-
}
33-
34-
$updateAccountFields = @()
35-
if ($account.PSObject.Properties.Name -Contains 'EmAd') {
36-
$updateAccountFields += "EmAd"
37-
}
38-
if ($account.PSObject.Properties.Name -Contains 'EmailPortal') {
39-
$updateAccountFields += "EmailPortal"
40-
}
41-
if ($account.PSObject.Properties.Name -Contains 'TeNr') {
42-
$updateAccountFields += "TeNr"
43-
}
44-
if ($account.PSObject.Properties.Name -Contains 'MbNr') {
45-
$updateAccountFields += "MbNr"
46-
}
47-
4818
#region functions
4919
function Resolve-HTTPError {
5020
[CmdletBinding()]
@@ -141,6 +111,37 @@ function Get-ErrorMessage {
141111

142112
# Get current account and verify if there are changes
143113
try {
114+
$account = $actionContext.Data
115+
116+
$correlationProperty = $actionContext.CorrelationConfiguration.accountField
117+
$correlationValue = $actionContext.References.Account.Medewerker # Has to match the AFAS value of the specified filter field ($filterfieldid)
118+
119+
$updateAccountFields = @()
120+
if ($account.PSObject.Properties.Name -Contains 'EmAd') {
121+
$updateAccountFields += "EmAd"
122+
}
123+
if ($account.PSObject.Properties.Name -Contains 'EmailPortal') {
124+
$updateAccountFields += "EmailPortal"
125+
}
126+
if ($account.PSObject.Properties.Name -Contains 'TeNr') {
127+
$updateAccountFields += "TeNr"
128+
}
129+
if ($account.PSObject.Properties.Name -Contains 'MbNr') {
130+
$updateAccountFields += "MbNr"
131+
}
132+
133+
# Verify if [aRef] has a value
134+
if ([string]::IsNullOrEmpty($($actionContext.References.Account))) {
135+
$outputContext.AuditLogs.Add([PSCustomObject]@{
136+
Action = "UpdateAccount"
137+
Message = "The account reference could not be found"
138+
IsError = $true
139+
})
140+
141+
throw 'The account reference could not be found'
142+
}
143+
144+
144145
try {
145146
Write-Verbose "Querying AFAS employee where [$($correlationProperty)] = [$($correlationValue)]"
146147

@@ -218,7 +219,7 @@ try {
218219
}
219220

220221
# Skip further actions, as this is a critical error
221-
continue
222+
throw "Error querying AFAS employee"
222223
}
223224

224225
switch ($updateAction) {
@@ -310,8 +311,9 @@ try {
310311
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)"
311312
IsError = $true
312313
})
314+
# Skip further actions, as this is a critical error
315+
throw "Error updating AFAS employee"
313316
}
314-
315317
break
316318
}
317319
'NoChanges' {
@@ -338,6 +340,10 @@ try {
338340
}
339341
}
340342
}
343+
catch {
344+
$ex = $PSItem
345+
Write-Verbose "ERROR: $ex"
346+
}
341347
finally {
342348
# Check if auditLogs contains errors, if errors are found, set succes to false
343349
if ($outputContext.AuditLogs.IsError -contains $true) {

fieldMapping.json

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"Version": "v1",
3+
"MappingFields": [
4+
{
5+
"Name": "Medewerker",
6+
"Description": "[Mandatory]",
7+
"Type": "Text",
8+
"MappingActions": [
9+
{
10+
"MapForActions": [
11+
"Create",
12+
"Update"
13+
],
14+
"MappingMode": "Field",
15+
"Value": "\"Person.ExternalId\"",
16+
"UsedInNotifications": false,
17+
"StoreInAccountData": true
18+
}
19+
]
20+
},
21+
{
22+
"Name": "Persoonsnummer",
23+
"Description": "[Mandatory]",
24+
"Type": "Text",
25+
"MappingActions": [
26+
{
27+
"MapForActions": [
28+
"Create",
29+
"Update"
30+
],
31+
"MappingMode": "None",
32+
"Value": "\"\"",
33+
"UsedInNotifications": false,
34+
"StoreInAccountData": true
35+
}
36+
]
37+
},
38+
{
39+
"Name": "EmAd",
40+
"Description": "",
41+
"Type": "Text",
42+
"MappingActions": [
43+
{
44+
"MapForActions": [
45+
"Create",
46+
"Update"
47+
],
48+
"MappingMode": "Complex",
49+
"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()\"",
50+
"UsedInNotifications": false,
51+
"StoreInAccountData": true
52+
},
53+
{
54+
"MapForActions": [
55+
"Delete"
56+
],
57+
"MappingMode": "Fixed",
58+
"Value": "\"\"",
59+
"UsedInNotifications": false,
60+
"StoreInAccountData": false
61+
}
62+
]
63+
}
64+
],
65+
"UniqueFieldNames": []
66+
}

0 commit comments

Comments
 (0)