@@ -145,31 +145,58 @@ function New-ServiceNowQuery {
145145 if ( $i -eq $filterList.Count - 1 ) {
146146 throw ' $Filter cannot end with a join'
147147 }
148+
149+ break
148150 }
149151
150- 2 {
151- # should be a non-value operator, eg. ='' / ISEMPTY
152+ { $_ -ne 1 } {
153+ # perform data validation on all filters other than a join operator
152154 $thisOperator = $script :ServiceNowOperator | Where-Object { $_.Name -eq $thisFilter [1 ] }
153155 if ( -not $thisOperator ) {
154156 throw (' Operator '' {0}'' is not valid' -f $thisFilter [1 ])
155157 }
156- if ( $thisOperator.RequiresValue ) {
157- throw (' Value not provided, {0} {1} ? ' -f $thisFilter [0 ], $thisOperator.QueryOperator )
158+ if ( $thisOperator.NumValues -ne $thisFilter .Count - 2 ) {
159+ throw (' Operator '' {0}'' requires 1 field name and {1} value(s) ' -f $thisFilter [1 ], $thisOperator.NumValues )
158160 }
161+ }
162+
163+ 2 {
164+ # should be a non-value operator, eg. ='' / ISEMPTY
159165 ' {0}{1}' -f $thisFilter [0 ], $thisOperator.QueryOperator
166+ break
160167 }
161168
162169 3 {
163- # should be field operator value
164- $thisOperator = $script :ServiceNowOperator | Where-Object { $_.Name -eq $thisFilter [1 ] }
165- if ( -not $thisOperator ) {
166- throw (' Operator '' {0}'' is not valid' , $thisFilter [1 ])
170+ # should be format - field operator value
171+
172+ if ( $thisFilter [2 ] -is [DateTime ] ) {
173+ $dateGen = " '{0}','{1}'" -f $thisFilter [2 ].ToString(' yyyy-MM-dd' ), $thisFilter [2 ].ToString(' HH:mm:ss' )
174+ ' {0}{1}javascript:gs.dateGenerate({2})' -f $thisFilter [0 ], $thisOperator.QueryOperator , $dateGen
175+ }
176+ else {
177+ ' {0}{1}{2}' -f $thisFilter [0 ], $thisOperator.QueryOperator , $thisFilter [2 ]
167178 }
168- ' {0}{1}{2}' -f $thisFilter [0 ], $thisOperator.QueryOperator , $thisFilter [2 ]
179+
180+ break
181+ }
182+
183+ 4 {
184+ # should be format - field operator value1 value2, where applicable, eg. between
185+
186+ if ( $thisFilter [2 ] -is [DateTime ] ) {
187+ $dateGen1 = " '{0}','{1}'" -f $thisFilter [2 ].ToString(' yyyy-MM-dd' ), $thisFilter [2 ].ToString(' HH:mm:ss' )
188+ $dateGen2 = " '{0}','{1}'" -f $thisFilter [3 ].ToString(' yyyy-MM-dd' ), $thisFilter [3 ].ToString(' HH:mm:ss' )
189+ ' {0}{1}javascript:gs.dateGenerate({2})@javascript:gs.dateGenerate({3})' -f $thisFilter [0 ], $thisOperator.QueryOperator , $dateGen1 , $dateGen2
190+ }
191+ else {
192+ ' {0}{1}{2}@{3}' -f $thisFilter [0 ], $thisOperator.QueryOperator , $thisFilter [2 ], $thisFilter [3 ]
193+ }
194+
195+ break
169196 }
170197
171198 Default {
172- throw (' Too many items for {0}, see the help' -f $thisFilter [0 ])
199+ throw (' Too many filter items for {0}, see the help' -f $thisFilter [0 ])
173200 }
174201 }
175202 }
@@ -234,7 +261,7 @@ function New-ServiceNowQuery {
234261 }
235262 }
236263
237- $query -join ' '
264+ ( $query -join ' ' ).Trim( ' ^ ' )
238265
239266 }
240267 else {
0 commit comments