Skip to content

Commit

Permalink
Fix New-ServiceNowChangeTask not linking to parent (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
gdbarron authored Nov 19, 2023
1 parent 2971be1 commit b9e890d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
10 changes: 5 additions & 5 deletions ServiceNow/Public/New-ServiceNowChangeRequest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
.PARAMETER ConfigurationItem
Full name or sys_id of the configuration item to be associated with the change
.PARAMETER InputData
.PARAMETER CustomField
Field values which aren't one of the built in function properties
.PARAMETER ServiceNowSession
Expand Down Expand Up @@ -109,8 +109,8 @@ function New-ServiceNowChangeRequest {
[string] $ConfigurationItem,

[parameter()]
[Alias('CustomFields')]
[hashtable] $InputData,
[Alias('CustomFields', 'InputData')]
[hashtable] $CustomField,

[Parameter()]
[Hashtable] $Connection,
Expand Down Expand Up @@ -141,12 +141,12 @@ function New-ServiceNowChangeRequest {
}

# add custom fields
$duplicateValues = ForEach ($Key in $InputData.Keys) {
$duplicateValues = ForEach ($Key in $CustomField.Keys) {
If ( $values.ContainsKey($Key) ) {
$Key
}
Else {
$values.Add($Key, $InputData[$Key])
$values.Add($Key, $CustomField[$Key])
}
}

Expand Down
11 changes: 6 additions & 5 deletions ServiceNow/Public/New-ServiceNowChangeTask.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function New-ServiceNowChangeTask {
Return the newly created item details
.EXAMPLE
New-ServiceNowChangeTask -ChangeRequest RITM0010001 -ShortDescription 'New PS change request' -Description 'This change request was created from Powershell' -AssignmentGroup ServiceDesk
New-ServiceNowChangeTask -ChangeRequest CHG0010001 -ShortDescription 'New PS change request' -Description 'This change request was created from Powershell' -AssignmentGroup ServiceDesk
Create a new task
Expand Down Expand Up @@ -82,6 +82,7 @@ function New-ServiceNowChangeTask {
switch ($PSBoundParameters.Keys) {
'ChangeRequest' {
$createValues.parent = $ChangeRequest
$createValues.change_request = $ChangeRequest
}

'ShortDescription' {
Expand All @@ -101,11 +102,11 @@ function New-ServiceNowChangeTask {
}
}

$CustomField.GetEnumerator() | ForEach-Object {
if ( $createValues.($_.Key) ) {
Write-Warning ('Custom field {0} has already been added via parameter' -f $_.Key)
foreach ($key in $CustomField.Keys) {
if ( $createValues.$key ) {
Write-Warning "Custom field '$key' has already been provided via one of the dedicated parameters"
} else {
$createValues.Add($_.Key, $_.Value)
$createValues.Add($key, $CustomField.$key)
}
}

Expand Down
12 changes: 6 additions & 6 deletions ServiceNow/Public/New-ServiceNowIncident.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Generates a new ServiceNow Incident using predefined or other field values
.PARAMETER ConfigurationItem
Full name or sys_id of the configuration item to be associated with the change
.PARAMETER InputData
.PARAMETER CustomField
Field values which aren't one of the built in function properties
.PARAMETER ServiceNowSession
Expand All @@ -56,7 +56,7 @@ Generate a basic Incident attributed to the caller "UserName" with descriptions,
Category = "Office"
Subcategory = "Outlook"
ConfigurationItem = "UserPC1"
InputData = @{u_custom1 = "Custom Field Entry"
CustomField = @{u_custom1 = "Custom Field Entry"
u_another_custom = "Related Test"}
}
New-ServiceNowIncident @IncidentParams
Expand Down Expand Up @@ -93,8 +93,8 @@ function New-ServiceNowIncident {
[string] $ConfigurationItem,

[parameter()]
[Alias('CustomFields')]
[hashtable] $InputData,
[Alias('CustomFields', 'InputData')]
[hashtable] $CustomField,

[Parameter()]
[Hashtable] $Connection,
Expand Down Expand Up @@ -124,12 +124,12 @@ function New-ServiceNowIncident {
}

# add custom fields
$duplicateValues = ForEach ($Key in $InputData.Keys) {
$duplicateValues = ForEach ($Key in $CustomField.Keys) {
If ( $values.ContainsKey($Key) ) {
$Key
}
Else {
$values.Add($Key, $InputData[$Key])
$values.Add($Key, $CustomField[$Key])
}
}

Expand Down

0 comments on commit b9e890d

Please sign in to comment.