@@ -151,7 +151,8 @@ function Get-ServiceNowRecord {
151
151
[ValidateScript ( {
152
152
if ($_ -match ' ^[a-zA-Z0-9]{32}$' -or $_ -match ' ^([a-zA-Z]+)[0-9]+$' ) {
153
153
$true
154
- } else {
154
+ }
155
+ else {
155
156
throw ' Id must be either a 32 character alphanumeric, ServiceNow sysid, or prefix/id, ServiceNow number.'
156
157
}
157
158
})]
@@ -162,7 +163,8 @@ function Get-ServiceNowRecord {
162
163
[ValidateScript ( {
163
164
if ($_ -match ' ^[a-zA-Z0-9]{32}$' -or $_ -match ' ^([a-zA-Z]+)[0-9]+$' ) {
164
165
$true
165
- } else {
166
+ }
167
+ else {
166
168
throw ' ParentId must be either a 32 character alphanumeric, ServiceNow sysid, or prefix/id, ServiceNow number.'
167
169
}
168
170
})]
@@ -241,7 +243,8 @@ function Get-ServiceNowRecord {
241
243
}
242
244
243
245
$idFilter = @ (' sys_id' , ' -eq' , $ID )
244
- } else {
246
+ }
247
+ else {
245
248
if ( -not $thisTable ) {
246
249
# get table name from prefix if only Id was provided
247
250
$idPrefix = ($ID | Select-String - Pattern ' ^([a-zA-Z]+)([0-9]+$)' ).Matches.Groups[1 ].Value.ToLower()
@@ -256,7 +259,8 @@ function Get-ServiceNowRecord {
256
259
257
260
if ( $invokeParams.Filter ) {
258
261
$invokeParams.Filter = $invokeParams.Filter , ' and' , $idFilter
259
- } else {
262
+ }
263
+ else {
260
264
$invokeParams.Filter = $idFilter
261
265
}
262
266
@@ -268,13 +272,15 @@ function Get-ServiceNowRecord {
268
272
if ( $ParentID ) {
269
273
if ( $ParentID -match ' ^[a-zA-Z0-9]{32}$' ) {
270
274
$parentIdFilter = @ (' parent.sys_id' , ' -eq' , $ParentID )
271
- } else {
275
+ }
276
+ else {
272
277
$parentIdFilter = @ (' parent.number' , ' -eq' , $ParentID )
273
278
}
274
279
275
280
if ( $invokeParams.Filter ) {
276
281
$invokeParams.Filter = $invokeParams.Filter , ' and' , $parentIdFilter
277
- } else {
282
+ }
283
+ else {
278
284
$invokeParams.Filter = $parentIdFilter
279
285
}
280
286
}
@@ -288,7 +294,8 @@ function Get-ServiceNowRecord {
288
294
289
295
if ( $invokeParams.Filter ) {
290
296
$invokeParams.Filter = $invokeParams.Filter , ' and' , @ ($thisTable.DescriptionField , ' -like' , $Description )
291
- } else {
297
+ }
298
+ else {
292
299
$invokeParams.Filter = @ ($thisTable.DescriptionField , ' -like' , $Description )
293
300
}
294
301
}
@@ -317,10 +324,14 @@ function Get-ServiceNowRecord {
317
324
# for each record, get the variable names and then get the variable values
318
325
foreach ($record in $result ) {
319
326
327
+ $recordSysId = if ($DisplayValue -eq ' all' ) { $record.sys_id.value } else { $record.sys_id }
328
+
329
+ # YES_NO = 1; MULTI_LINE_TEXT = 2; MULTIPLE_CHOICE = 3; NUMERIC_SCALE = 4; SELECT_BOX = 5; SINGLE_LINE_TEXT = 6; CHECKBOX = 7; REFERENCE = 8; DATE = 9; DATE_TIME = 10; LABEL = 11; BREAK = 12; MACRO = 14; UI_PAGE = 15; WIDE_SINGLE_LINE_TEXT = 16; MACRO_WITH_LABEL = 17; LOOKUP_SELECT_BOX = 18; CONTAINER_START = 19; CONTAINER_END = 20; LIST_COLLECTOR = 21; LOOKUP_MULTIPLE_CHOICE = 22; HTML = 23; SPLIT = 24; MASKED = 25;
330
+
320
331
$customVarParams = @ {
321
332
Table = ' sc_item_option_mtom'
322
- Filter = @ (' request_item' , ' -eq' , $record .sys_id ), ' and' , @ (' sc_item_option.item_option_new.type' , ' -in' , ' 1,2,3,4,5,6,7,8,9,10,16,18,21,22,26' )
323
- Property = ' sc_item_option.item_option_new.name' , ' sc_item_option.value' , ' sc_item_option.item_option_new.type' , ' sc_item_option.item_option_new.question_text'
333
+ Filter = @ (' request_item' , ' -eq' , $recordSysId ), ' and' , @ (' sc_item_option.item_option_new.type' , ' -in' , ' 1,2,3,4,5,6,7,8,9,10,16,18,21,22,26' )
334
+ Property = ' sc_item_option.item_option_new.name' , ' sc_item_option.value' , ' sc_item_option.item_option_new.type' , ' sc_item_option.item_option_new.question_text' , ' sc_item_option.item_option_new.reference '
324
335
IncludeTotalCount = $true
325
336
ServiceNowSession = $ServiceNowSession
326
337
}
@@ -333,16 +344,23 @@ function Get-ServiceNowRecord {
333
344
$record | Add-Member @ {
334
345
' CustomVariable' = [pscustomobject ]@ {}
335
346
}
347
+
336
348
foreach ($var in $customVarsOut ) {
337
- $record.CustomVariable | Add-Member @ {
338
- $var .' sc_item_option.item_option_new.name' = [pscustomobject ] @ {
339
- Value = $var .' sc_item_option.value'
340
- DisplayName = $var .' sc_item_option.item_option_new.question_text'
341
- Type = $var .' sc_item_option.item_option_new.type'
342
- }
349
+ $newVar = [pscustomobject ] @ {
350
+ Value = $var .' sc_item_option.value'
351
+ DisplayName = $var .' sc_item_option.item_option_new.question_text'
352
+ Type = $var .' sc_item_option.item_option_new.type'
353
+ }
354
+
355
+ # show the underlying value if the option is a reference type
356
+ if ($newVar.Type -eq ' Reference' ) {
357
+ $newVar.Value = (Get-ServiceNowRecord - Table $var .' sc_item_option.item_option_new.reference' - ID $var .' sc_item_option.value' - Property name - AsValue - ServiceNowSession $ServiceNowSession )
343
358
}
359
+
360
+ $record.CustomVariable | Add-Member @ { $var .' sc_item_option.item_option_new.name' = $newVar }
344
361
}
345
- } else {
362
+ }
363
+ else {
346
364
347
365
Write-Warning ' The format for custom variables will soon change. Start using -New with -IncludeCustomVariable to preview.'
348
366
@@ -370,22 +388,26 @@ function Get-ServiceNowRecord {
370
388
371
389
if ( $addedSysIdProp ) {
372
390
$record | Select-Object - Property * - ExcludeProperty sys_id
373
- } else {
391
+ }
392
+ else {
374
393
$record
375
394
}
376
395
}
377
396
378
- } else {
397
+ }
398
+ else {
379
399
380
400
# format the results
381
401
if ( $Property ) {
382
402
if ( $Property.Count -eq 1 -and $AsValue ) {
383
403
$propName = $result | Get-Member | Where-Object { $_.MemberType -eq ' NoteProperty' } | Select-Object - exp Name
384
404
$result | Select-Object - ExpandProperty $propName
385
- } else {
405
+ }
406
+ else {
386
407
$result
387
408
}
388
- } else {
409
+ }
410
+ else {
389
411
if ($thisTable.Type ) {
390
412
$result | ForEach-Object { $_.PSObject.TypeNames.Insert (0 , $thisTable.Type ) }
391
413
}
0 commit comments