Skip to content

Commit 0edcf5a

Browse files
authored
table name conversion for Get-ServiceNowAttachment (#177)
1 parent b3fc819 commit 0edcf5a

File tree

3 files changed

+32
-21
lines changed

3 files changed

+32
-21
lines changed

RELEASE.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
- Add email type to custom variables, [#173](https://github.com/Snow-Shell/servicenow-powershell/issues/173)
1+
- Add table name translation to `Get-ServiceNowAttachment` where sys_class_name does not match table name
2+
- Change .endswith operator from % to ENDSWITH as % was not working

ServiceNow/Public/Get-ServiceNowAttachment.ps1

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11

22
Function Get-ServiceNowAttachment {
33
<#
4-
4+
55
.SYNOPSIS
66
Retrieve attachment details
7-
7+
88
.DESCRIPTION
99
Retrieve attachment details via table record or by advanced filtering.
10-
10+
1111
.PARAMETER Table
1212
Name of the table to be queried, by either table name or class name. Use tab completion for list of known tables.
1313
You can also provide any table name ad hoc.
14-
14+
1515
.PARAMETER Id
1616
Either the record sys_id or number.
1717
If providing just an Id, not with Table, the Id prefix will be looked up to find the table name.
18-
18+
1919
.PARAMETER FileName
2020
Filter for a specific file name or part of a file name.
21-
21+
2222
.PARAMETER Filter
2323
Array or multidimensional array of fields and values to filter on.
2424
Each array should be of the format @(field, comparison operator, value) separated by a join, either 'and', 'or', or 'group'.
@@ -39,19 +39,19 @@ Function Get-ServiceNowAttachment {
3939
4040
.EXAMPLE
4141
Get-ServiceNowAttachment -Id 'INC1234567'
42-
42+
4343
Get attachment details for a specific record
44-
44+
4545
.EXAMPLE
4646
Get-ServiceNowAttachment -Id 'INC1234567' -FileName image.jpg
47-
47+
4848
Get attachment details for a specific record where file names match all or part of image.jpg
49-
49+
5050
.EXAMPLE
5151
Get-ServiceNowAttachment -Filter @('size_bytes', '-gt', '1000000')
52-
52+
5353
Get attachment details where size is greater than 1M.
54-
54+
5555
.INPUTS
5656
Table, Id
5757
@@ -112,17 +112,20 @@ Function Get-ServiceNowAttachment {
112112
$getParams.Table = $Table
113113
}
114114
$tableRecord = Get-ServiceNowRecord @getParams
115-
115+
116116
if ( -not $tableRecord ) {
117117
Write-Error "Record not found for Id '$Id'"
118118
continue
119119
}
120-
121-
$params.Filter = @(
122-
@('table_name', '-eq', $tableRecord.sys_class_name),
123-
'and',
124-
@('table_sys_id', '-eq', $tableRecord.sys_id)
125-
)
120+
121+
# perform lookup for known table names which might be different than sys_class_name
122+
$tableName = $script:ServiceNowTable | Where-Object { $_.Name.ToLower() -eq $tableRecord.sys_class_name.ToLower() -or $_.ClassName.ToLower() -eq $tableRecord.sys_class_name.ToLower() } | Select-Object -ExpandProperty Name
123+
if ( $tableName ) {
124+
$params.Filter = @(@('table_name', '-eq', $tableName), 'and', @('table_sys_id', '-eq', $tableRecord.sys_id))
125+
}
126+
else {
127+
$params.Filter = @(@('table_name', '-eq', $tableRecord.sys_class_name), 'and', @('table_sys_id', '-eq', $tableRecord.sys_id))
128+
}
126129
}
127130

128131
if ( $FileName ) {

ServiceNow/config/main.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@
6161
"Type": "ServiceNow.ChangeTask",
6262
"NumberPrefix": "ctask",
6363
"DescriptionField": "short_description"
64+
},
65+
{
66+
"Name": "cmdb_ci_certificate",
67+
"ClassName": "Unique Certificate",
68+
"Type": "ServiceNow.UniqueCertificate",
69+
"NumberPrefix": "",
70+
"DescriptionField": "name"
6471
}
6572
],
6673
"FilterOperators": [
@@ -162,7 +169,7 @@
162169
},
163170
{
164171
"Name": ".endswith",
165-
"QueryOperator": "%",
172+
"QueryOperator": "ENDSWITH",
166173
"Description": "field ends with the value",
167174
"NumValues": 1
168175
},

0 commit comments

Comments
 (0)