@@ -183,8 +183,7 @@ function Get-ServiceNowRecord {
183
183
[ValidateScript ( {
184
184
if ($_ -match ' ^[a-zA-Z0-9]{32}$' -or $_ -match ' ^([a-zA-Z]+)[0-9]+$' ) {
185
185
$true
186
- }
187
- else {
186
+ } else {
188
187
throw ' Id must either be a SysId 32 character alphanumeric or Number with prefix and id.'
189
188
}
190
189
})]
@@ -195,8 +194,7 @@ function Get-ServiceNowRecord {
195
194
[ValidateScript ( {
196
195
if ($_ -match ' ^[a-zA-Z0-9]{32}$' -or $_ -match ' ^([a-zA-Z]+)[0-9]+$' ) {
197
196
$true
198
- }
199
- else {
197
+ } else {
200
198
throw ' ParentId must either be a SysId 32 character alphanumeric or Number with prefix and id.'
201
199
}
202
200
})]
@@ -287,8 +285,7 @@ function Get-ServiceNowRecord {
287
285
288
286
if ( $thisID -match ' ^[a-zA-Z0-9]{32}$' ) {
289
287
$thisParams.Filter += , @ (' sys_id' , ' -eq' , $thisID )
290
- }
291
- else {
288
+ } else {
292
289
$thisParams.Filter += , @ (' number' , ' -eq' , $thisID )
293
290
}
294
291
}
@@ -301,8 +298,7 @@ function Get-ServiceNowRecord {
301
298
302
299
if ( $ParentID -match ' ^[a-zA-Z0-9]{32}$' ) {
303
300
$thisParams.Filter += , @ (' parent.sys_id' , ' -eq' , $ParentID )
304
- }
305
- else {
301
+ } else {
306
302
$thisParams.Filter += , @ (' parent.number' , ' -eq' , $ParentID )
307
303
}
308
304
@@ -381,43 +377,50 @@ function Get-ServiceNowRecord {
381
377
382
378
# show the underlying value if the option is a reference type
383
379
if ( $newVar.Type -eq ' Reference' ) {
384
- $newVar | Add-Member @ {' ReferenceTable' = $var .' sc_item_option.item_option_new.reference' }
385
- # issue 234. ID might not be sysid or number for reference...odd
386
- $refValue = Get-ServiceNowRecord - Table $var .' sc_item_option.item_option_new.reference' - ID $var .' sc_item_option.value' - Property name - AsValue - ServiceNowSession $ServiceNowSession - ErrorAction SilentlyContinue
387
- if ( $refValue ) {
388
- $newVar.Value = $refValue
380
+ # do not do any further lookup when the value is blank or null
381
+ # resolves #234 and 262
382
+ if ($var .' sc_item_option.value' -eq " " -or $null -eq $var .' sc_item_option.value' ) {
383
+ continue
389
384
}
385
+ $sysidPattern = " [0-9a-fA-F]{32}"
386
+ $sysid = [Regex ]::Matches($var .' sc_item_option.value' , $sysidPattern ).Value
387
+ if ($sysid ) {
388
+ Write-Verbose " Custom variable lookup for $ ( $newvar.name ) from table '$ ( $var .' sc_item_option.item_option_new.reference' ) ' sysid:'$ ( $var .' sc_item_option.value' ) '"
389
+ $newVar | Add-Member @ {' ReferenceTable' = $var .' sc_item_option.item_option_new.reference' }
390
+ $newVar | Add-Member @ {' ReferenceID' = $var .' sc_item_option.value' }
391
+ # issue 234. ID might not be sysid or number for reference...odd
392
+ $refValue = Get-ServiceNowRecord - Table $var .' sc_item_option.item_option_new.reference' - ID $var .' sc_item_option.value' - Property name - AsValue - ServiceNowSession $ServiceNowSession - ErrorAction SilentlyContinue
393
+ if ( $refValue ) {
394
+ $newVar.Value = $refValue
395
+ }
396
+ }
397
+
390
398
}
391
399
392
400
if ( $var .' sc_item_option.item_option_new.name' ) {
393
401
$record.CustomVariable | Add-Member @ { $var .' sc_item_option.item_option_new.name' = $newVar }
394
- }
395
- else {
402
+ } else {
396
403
$record.CustomVariable | Add-Member @ { $var .' sc_item_option.item_option_new.question_text' = $newVar }
397
404
}
398
405
}
399
406
400
407
if ( $addedSysIdProp ) {
401
408
$record | Select-Object - Property * - ExcludeProperty sys_id
402
- }
403
- else {
409
+ } else {
404
410
$record
405
411
}
406
412
}
407
- }
408
- else {
413
+ } else {
409
414
410
415
# format the results
411
416
if ( $Property ) {
412
417
if ( $Property.Count -eq 1 -and $AsValue ) {
413
418
$propName = $result | Get-Member | Where-Object { $_.MemberType -eq ' NoteProperty' } | Select-Object - ExpandProperty Name
414
419
$result .$propName
415
- }
416
- else {
420
+ } else {
417
421
$result
418
422
}
419
- }
420
- else {
423
+ } else {
421
424
if ($thisTable.Type ) {
422
425
$result | ForEach-Object { $_.PSObject.TypeNames.Insert (0 , $thisTable.Type ) }
423
426
}
0 commit comments