3333 For a complete list of comparison operators, see $script:ServiceNowOperator and use Name in your filter.
3434 See the examples.
3535
36+ . PARAMETER FilterString
37+ A string representation of the filter. This is useful when the filter is complex and hard to specify as an array.
38+ Retrieve the filter string from the ServiceNow UI via right click on the filter and selecting 'Copy query'.
39+
3640. PARAMETER Sort
3741 Array or multidimensional array of fields to sort on.
3842 Each array should be of the format @(field, asc/desc).
143147
144148 Get a specific record by number using the function alias
145149
150+ . EXAMPLE
151+ Get-ServiceNowRecord -Table 'incident' -FilterString 'active=true^state=1'
152+
153+ Provide a filter string from the UI to get records where active is true and state is 1
154+
146155. INPUTS
147156 ID
148157
@@ -165,6 +174,7 @@ function Get-ServiceNowRecord {
165174 [Parameter (ParameterSetName = ' Table' , Mandatory )]
166175 [Parameter (ParameterSetName = ' TableId' , Mandatory )]
167176 [Parameter (ParameterSetName = ' TableParentId' )]
177+ [Parameter (ParameterSetName = ' FilterString' , Mandatory )]
168178 [Alias (' sys_class_name' )]
169179 [string ] $Table ,
170180
@@ -204,6 +214,10 @@ function Get-ServiceNowRecord {
204214 [Parameter (ParameterSetName = ' TableParentId' )]
205215 [object []] $Filter = @ (),
206216
217+ [Parameter (ParameterSetName = ' FilterString' , Mandatory )]
218+ [Alias (' fs' )]
219+ [string ] $FilterString ,
220+
207221 [Parameter (ParameterSetName = ' Table' )]
208222 [Parameter (ParameterSetName = ' TableParentId' )]
209223 [ValidateNotNullOrEmpty ()]
@@ -234,7 +248,6 @@ function Get-ServiceNowRecord {
234248 process {
235249
236250 $thisParams = @ {
237- Filter = $Filter
238251 Property = $Property
239252 Sort = $Sort
240253 DisplayValue = $DisplayValue
@@ -246,13 +259,18 @@ function Get-ServiceNowRecord {
246259 }
247260
248261 if ( $PSBoundParameters.ContainsKey (' Filter' ) ) {
262+ $thisParams.Filter = $Filter
249263 # # we always want the filter to be arrays separated by joins
250264 if ( $Filter [0 ].GetType().Name -ne ' Object[]' ) {
251265 #
252266 $thisParams.Filter = , $Filter
253267 }
254268 }
255269
270+ if ( $FilterString ) {
271+ $thisParams.FilterString = $FilterString
272+ }
273+
256274 $addedSysIdProp = $false
257275 # we need the sys_id value in order to get custom var data
258276 # add it in if specific properties were requested and not part of the list
0 commit comments