Skip to content

Commit 2036514

Browse files
authored
Merge pull request #57 from gdbarron/Issue45-Hashtable-keys-to-lower
set key names in query filters to lowercase
2 parents 4559599 + 361bcc3 commit 2036514

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

ServiceNow/Public/New-ServiceNowQuery.ps1

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,34 @@
1+
<#
2+
.SYNOPSIS
3+
Build query string for api call
4+
.DESCRIPTION
5+
Build query string for api call
6+
.EXAMPLE
7+
New-ServiceNowQuery -MatchExact @{field_name=value}
8+
Get query string where field name exactly matches the value
9+
.EXAMPLE
10+
New-ServiceNowQuery -MatchContains @{field_name=value}
11+
Get query string where field name contains the value
12+
.INPUTS
13+
None
14+
.OUTPUTS
15+
String
16+
#>
117
function New-ServiceNowQuery{
218

19+
[CmdletBinding()]
20+
[OutputType([System.String])]
21+
322
param(
423
# Machine name of the field to order by
524
[parameter(mandatory=$false)]
625
[string]$OrderBy='opened_at',
7-
26+
827
# Direction of ordering (Desc/Asc)
928
[parameter(mandatory=$false)]
1029
[ValidateSet("Desc", "Asc")]
1130
[string]$OrderDirection='Desc',
12-
31+
1332
# Hashtable containing machine field names and values returned must match exactly (will be combined with AND)
1433
[parameter(mandatory=$false)]
1534
[hashtable]$MatchExact,
@@ -30,14 +49,14 @@ function New-ServiceNowQuery{
3049
# Build the exact matches into the query
3150
if($MatchExact){
3251
foreach($Field in $MatchExact.keys){
33-
$Query += "^$Field="+$MatchExact.$Field
52+
$Query += "^{0}={1}" -f $Field.ToString().ToLower(), ($MatchExact.$Field)
3453
}
3554
}
3655

3756
# Add the values which given fields should contain
3857
if($MatchContains){
3958
foreach($Field in $MatchContains.keys){
40-
$Query += "^$($Field)LIKE"+$MatchContains.$Field
59+
$Query += "^{0}LIKE{1}" -f $Field.ToString().ToLower(), ($MatchContains.$Field)
4160
}
4261
}
4362

0 commit comments

Comments
 (0)