servicenow-powershell
servicenow-powershell copied to clipboard
JSON Square Brackets Added to Array's First and Last Objects
Environment
Operating System: Windows Server 2016
ServiceNow module version: 4.0.3
PowerShell version: 5.1
Steps to reproduce
$CIs = @('Server1', 'Server2')
$UpdateChangeRequestDetails = @{
u_affected_ci_list = $CIs
}
Update-ServiceNowRecord -ID $CHG -InputData $UpdateChangeRequestDetails -Verbose
Expected behavior
Field in ServiceNow should just be populated with Server1 & Server2
Actual behavior
Field in ServiceNow is populated with [Server1 & Server2]
Screenshots
Not sending an array and instead casting a single object as a string removes the brackets
[string]$CIs = 'Server1'
$UpdateChangeRequestDetails = @{
u_affected_ci_list = $CIs
}
Update-ServiceNowRecord -ID $CHG -InputData $UpdateChangeRequestDetails -Verbose
Sending a variable cast as a string with "array" objects separated by a comma adds them to the field separated by a line (i.e. unique entries) and no square brackets:
[string]$CIs = 'Server1, Server2'
$UpdateChangeRequestDetails = @{
u_affected_ci_list = $CIs
}
Update-ServiceNowRecord -ID $CHG -InputData $UpdateChangeRequestDetails -Verbose
So if the variable is an array:
[array]$CIs = @('Server1', 'Server2')
[string]$CIsString = $CIs -join', '
$UpdateChangeRequestDetails = @{
u_affected_ci_list = $CIsString
}
Update-ServiceNowRecord -ID $CHG -InputData $UpdateChangeRequestDetails -Verbose
Works, sending the data without brackets. Unsure what you can do with this info, I can build my script around it, not sure if this matters to anyone else or if I'm just using the function incorrectly.
Cheers _Fonz