Skip to content

Commit b9e890d

Browse files
authored
Fix New-ServiceNowChangeTask not linking to parent (#256)
1 parent 2971be1 commit b9e890d

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

ServiceNow/Public/New-ServiceNowChangeRequest.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
.PARAMETER ConfigurationItem
3636
Full name or sys_id of the configuration item to be associated with the change
3737
38-
.PARAMETER InputData
38+
.PARAMETER CustomField
3939
Field values which aren't one of the built in function properties
4040
4141
.PARAMETER ServiceNowSession
@@ -109,8 +109,8 @@ function New-ServiceNowChangeRequest {
109109
[string] $ConfigurationItem,
110110

111111
[parameter()]
112-
[Alias('CustomFields')]
113-
[hashtable] $InputData,
112+
[Alias('CustomFields', 'InputData')]
113+
[hashtable] $CustomField,
114114

115115
[Parameter()]
116116
[Hashtable] $Connection,
@@ -141,12 +141,12 @@ function New-ServiceNowChangeRequest {
141141
}
142142

143143
# add custom fields
144-
$duplicateValues = ForEach ($Key in $InputData.Keys) {
144+
$duplicateValues = ForEach ($Key in $CustomField.Keys) {
145145
If ( $values.ContainsKey($Key) ) {
146146
$Key
147147
}
148148
Else {
149-
$values.Add($Key, $InputData[$Key])
149+
$values.Add($Key, $CustomField[$Key])
150150
}
151151
}
152152

ServiceNow/Public/New-ServiceNowChangeTask.ps1

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function New-ServiceNowChangeTask {
3131
Return the newly created item details
3232
3333
.EXAMPLE
34-
New-ServiceNowChangeTask -ChangeRequest RITM0010001 -ShortDescription 'New PS change request' -Description 'This change request was created from Powershell' -AssignmentGroup ServiceDesk
34+
New-ServiceNowChangeTask -ChangeRequest CHG0010001 -ShortDescription 'New PS change request' -Description 'This change request was created from Powershell' -AssignmentGroup ServiceDesk
3535
3636
Create a new task
3737
@@ -82,6 +82,7 @@ function New-ServiceNowChangeTask {
8282
switch ($PSBoundParameters.Keys) {
8383
'ChangeRequest' {
8484
$createValues.parent = $ChangeRequest
85+
$createValues.change_request = $ChangeRequest
8586
}
8687

8788
'ShortDescription' {
@@ -101,11 +102,11 @@ function New-ServiceNowChangeTask {
101102
}
102103
}
103104

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

ServiceNow/Public/New-ServiceNowIncident.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Generates a new ServiceNow Incident using predefined or other field values
2929
.PARAMETER ConfigurationItem
3030
Full name or sys_id of the configuration item to be associated with the change
3131
32-
.PARAMETER InputData
32+
.PARAMETER CustomField
3333
Field values which aren't one of the built in function properties
3434
3535
.PARAMETER ServiceNowSession
@@ -56,7 +56,7 @@ Generate a basic Incident attributed to the caller "UserName" with descriptions,
5656
Category = "Office"
5757
Subcategory = "Outlook"
5858
ConfigurationItem = "UserPC1"
59-
InputData = @{u_custom1 = "Custom Field Entry"
59+
CustomField = @{u_custom1 = "Custom Field Entry"
6060
u_another_custom = "Related Test"}
6161
}
6262
New-ServiceNowIncident @IncidentParams
@@ -93,8 +93,8 @@ function New-ServiceNowIncident {
9393
[string] $ConfigurationItem,
9494

9595
[parameter()]
96-
[Alias('CustomFields')]
97-
[hashtable] $InputData,
96+
[Alias('CustomFields', 'InputData')]
97+
[hashtable] $CustomField,
9898

9999
[Parameter()]
100100
[Hashtable] $Connection,
@@ -124,12 +124,12 @@ function New-ServiceNowIncident {
124124
}
125125

126126
# add custom fields
127-
$duplicateValues = ForEach ($Key in $InputData.Keys) {
127+
$duplicateValues = ForEach ($Key in $CustomField.Keys) {
128128
If ( $values.ContainsKey($Key) ) {
129129
$Key
130130
}
131131
Else {
132-
$values.Add($Key, $InputData[$Key])
132+
$values.Add($Key, $CustomField[$Key])
133133
}
134134
}
135135

0 commit comments

Comments
 (0)