Skip to content

Commit c5a6fbd

Browse files
authored
fix 183 (#184)
1 parent 9811f68 commit c5a6fbd

File tree

3 files changed

+44
-17
lines changed

3 files changed

+44
-17
lines changed

RELEASE.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
- Fix #172, `Get-ServiceNowRecord -IncludeCustomVariable` not returning values
2-
- `Get-ServiceNowRecord -IncludeCustomVariable` 'variable.' prefix has been removed from custom variable property name.
3-
- Add pipeline functionality to `-Id` parameter of `Get-ServiceNowRecord`
4-
- Fix `Get-ServiceNowRecord -AsValue` causing error with some values
1+
- Fix [#183](https://github.com/Snow-Shell/servicenow-powershell/issues/183), `Get-ServiceNowRecord -Filter` parameter not applying in some circumstances
2+
- Update display formats to correctly show values when `-DisplayValue` is false
3+
- Update `Get-ServiceNowRecord` help

ServiceNow/Public/Get-ServiceNowRecord.ps1

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
1717
.PARAMETER ParentId
1818
The sys_id or number of the parent record.
19-
For example, to get catalog tasks for a requested item, provide the RITM number as ParentId.
19+
For example, to get catalog tasks for a requested item, provide the RITM number as ParentId and catalog task as the Table.
2020
2121
.PARAMETER Description
2222
Filter results based on the 'description' field. The field will be different for each table.
@@ -25,7 +25,7 @@
2525
The comparison performed is a 'like'.
2626
2727
.PARAMETER Property
28-
Return one or more specific fields
28+
Return one or more specific fields otherwise all fields will be returned
2929
3030
.PARAMETER Filter
3131
Array or multidimensional array of fields and values to filter on.
@@ -119,13 +119,16 @@
119119
Get a specific record by number using the function alias
120120
121121
.INPUTS
122-
None
122+
Id
123123
124124
.OUTPUTS
125-
System.Management.Automation.PSCustomObject
125+
PSCustomObject. If -AsValue is used, the type will be the selected field.
126126
127127
.LINK
128128
https://docs.servicenow.com/bundle/quebec-platform-user-interface/page/use/common-ui-elements/reference/r_OpAvailableFiltersQueries.html
129+
130+
.LINK
131+
https://developer.servicenow.com/dev.do#!/reference/api/sandiego/rest/c_TableAPI#table-GET
129132
#>
130133
function Get-ServiceNowRecord {
131134

@@ -197,6 +200,7 @@ function Get-ServiceNowRecord {
197200
begin {
198201

199202
$invokeParams = @{
203+
Filter = $Filter
200204
Property = $Property
201205
Sort = $Sort
202206
DisplayValue = $DisplayValue
@@ -245,8 +249,8 @@ function Get-ServiceNowRecord {
245249
$idFilter = @('number', '-eq', $Id)
246250
}
247251

248-
if ( $Filter ) {
249-
$invokeParams.Filter = $Filter, 'and', $idFilter
252+
if ( $invokeParams.Filter ) {
253+
$invokeParams.Filter = $invokeParams.Filter, 'and', $idFilter
250254
}
251255
else {
252256
$invokeParams.Filter = $idFilter
@@ -291,7 +295,7 @@ function Get-ServiceNowRecord {
291295
$addedSysIdProp = $false
292296
# we need the sys_id value in order to get custom var data
293297
# add it in if specific properties were requested and not part of the list
294-
if ( $IncludeCustomVariable.IsPresent ) {
298+
if ( $IncludeCustomVariable ) {
295299
if ( $Property -and 'sys_id' -notin $Property ) {
296300
$invokeParams.Property += 'sys_id'
297301
$addedSysIdProp = $true

ServiceNow/ServiceNow.format.ps1xml

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,23 @@
5151
</TableColumnItem>
5252
<TableColumnItem>
5353
<ScriptBlock>
54-
$_.assigned_to.display_value
54+
if ($_.assigned_to.display_value) {
55+
$_.assigned_to.display_value
56+
} else {
57+
$_.assigned_to.value
58+
}
5559
</ScriptBlock>
5660
</TableColumnItem>
5761
<TableColumnItem>
5862
<PropertyName>approval</PropertyName>
5963
</TableColumnItem>
6064
<TableColumnItem>
6165
<ScriptBlock>
62-
$_.cmdb_ci.display_value
66+
if ($_.cmdb_ci.display_value) {
67+
$_.cmdb_ci.display_value
68+
} else {
69+
$_.cmdb_ci.value
70+
}
6371
</ScriptBlock>
6472
</TableColumnItem>
6573
<TableColumnItem>
@@ -116,7 +124,11 @@
116124
</TableColumnItem>
117125
<TableColumnItem>
118126
<ScriptBlock>
119-
$_.assigned_to.display_value
127+
if ($_.assigned_to.display_value) {
128+
$_.assigned_to.display_value
129+
} else {
130+
$_.assigned_to.value
131+
}
120132
</ScriptBlock>
121133
</TableColumnItem>
122134
<TableColumnItem>
@@ -176,7 +188,11 @@
176188
</TableColumnItem>
177189
<TableColumnItem>
178190
<ScriptBlock>
179-
$_.assigned_to.display_value
191+
if ($_.assigned_to.display_value) {
192+
$_.assigned_to.display_value
193+
} else {
194+
$_.assigned_to.value
195+
}
180196
</ScriptBlock>
181197
</TableColumnItem>
182198
<TableColumnItem>
@@ -367,7 +383,11 @@
367383
</TableColumnItem>
368384
<TableColumnItem>
369385
<ScriptBlock>
370-
$_.request_item.display_value
386+
if ($_.request_item.display_value) {
387+
$_.request_item.display_value
388+
} else {
389+
$_.request_item.value
390+
}
371391
</ScriptBlock>
372392
</TableColumnItem>
373393
</TableColumnItems>
@@ -420,7 +440,11 @@
420440
</TableColumnItem>
421441
<TableColumnItem>
422442
<ScriptBlock>
423-
$_.change_request.display_value
443+
if ($_.change_request.display_value) {
444+
$_.change_request.display_value
445+
} else {
446+
$_.change_request.value
447+
}
424448
</ScriptBlock>
425449
</TableColumnItem>
426450
</TableColumnItems>

0 commit comments

Comments
 (0)