@@ -360,10 +360,16 @@ function Invoke-ExecCustomData {
360
360
try {
361
361
$Mappings = Get-CIPPAzDataTableEntity @CustomDataMappingsTable | ForEach-Object {
362
362
$Mapping = $_.JSON | ConvertFrom-Json - AsHashtable
363
+
364
+ Write-Information ($Mapping | ConvertTo-Json - Depth 5 )
363
365
[PSCustomObject ]@ {
364
- id = $_.RowKey
365
- tenant = $Mapping.tenantFilter.label
366
- sourceDataset = $Mapping.sourceDataset.label
366
+ id = $_.RowKey
367
+ tenant = $Mapping.tenantFilter.label
368
+ dataset = $Mapping.extensionSyncDataset.label
369
+ sourceType = $Mapping.sourceType.label
370
+ directoryType = $Mapping.directoryObjectType.label
371
+ syncProperty = $Mapping.extensionSyncProperty.label
372
+ customDataAttribute = $Mapping.customDataAttribute.label
367
373
}
368
374
}
369
375
$Body = @ {
@@ -380,16 +386,16 @@ function Invoke-ExecCustomData {
380
386
}
381
387
}
382
388
}
383
- ' AddMapping ' {
389
+ ' AddEditMapping ' {
384
390
try {
385
391
$Mapping = $Request.Body.Mapping
386
392
if (! $Mapping ) {
387
393
throw ' Mapping data is missing in the request body.'
388
394
}
389
- $id = [Guid ]::NewGuid().ToString()
395
+ $MappingId = $Request .Body.id ?? [Guid ]::NewGuid().ToString()
390
396
$Entity = @ {
391
397
PartitionKey = ' Mapping'
392
- RowKey = $id
398
+ RowKey = [ string ] $MappingId
393
399
JSON = [string ]($Mapping | ConvertTo-Json - Depth 5 - Compress)
394
400
}
395
401
@@ -399,7 +405,7 @@ function Invoke-ExecCustomData {
399
405
$Body = @ {
400
406
Results = @ {
401
407
state = ' success'
402
- resultText = " Mapping with ID ' $ ( $id ) ' added successfully."
408
+ resultText = ' Mapping saved successfully.'
403
409
}
404
410
}
405
411
} catch {
@@ -413,6 +419,67 @@ function Invoke-ExecCustomData {
413
419
}
414
420
}
415
421
}
422
+ ' DeleteMapping' {
423
+ try {
424
+ $MappingId = $Request.Body.id
425
+ if (! $MappingId ) {
426
+ throw ' Mapping ID is missing in the request body.'
427
+ }
428
+
429
+ # Retrieve the mapping entity
430
+ $MappingEntity = Get-CIPPAzDataTableEntity @CustomDataMappingsTable - Filter " PartitionKey eq 'Mapping' and RowKey eq '$MappingId '"
431
+ if (! $MappingEntity ) {
432
+ throw " Mapping with ID '$MappingId ' not found."
433
+ }
434
+
435
+ # Delete the mapping entity
436
+ Remove-AzDataTableEntity @CustomDataMappingsTable - Entity $MappingEntity
437
+ Register-CIPPExtensionScheduledTasks
438
+ $Body = @ {
439
+ Results = @ {
440
+ state = ' success'
441
+ resultText = " Mapping deleted successfully."
442
+ }
443
+ }
444
+ } catch {
445
+ $Body = @ {
446
+ Results = @ (
447
+ @ {
448
+ state = ' error'
449
+ resultText = " Failed to delete mapping: $ ( $_.Exception.Message ) "
450
+ }
451
+ )
452
+ }
453
+ }
454
+ }
455
+ ' GetMapping' {
456
+ try {
457
+ $MappingId = $Request.Query.id
458
+ if (! $MappingId ) {
459
+ throw ' Mapping ID is missing in the request query.'
460
+ }
461
+
462
+ # Retrieve the mapping entity
463
+ $MappingEntity = Get-CIPPAzDataTableEntity @CustomDataMappingsTable - Filter " PartitionKey eq 'Mapping' and RowKey eq '$MappingId '"
464
+ if (! $MappingEntity ) {
465
+ throw " Mapping with ID '$MappingId ' not found."
466
+ }
467
+
468
+ $Mapping = $MappingEntity.JSON | ConvertFrom-Json
469
+ $Body = @ {
470
+ Results = $Mapping
471
+ }
472
+ } catch {
473
+ $Body = @ {
474
+ Results = @ (
475
+ @ {
476
+ state = ' error'
477
+ resultText = " Failed to retrieve mapping: $ ( $_.Exception.Message ) "
478
+ }
479
+ )
480
+ }
481
+ }
482
+ }
416
483
417
484
default {
418
485
$Body = @ {
0 commit comments