Skip to content

Commit 30991c0

Browse files
Create function Get-ServiceNowRequestItem
This function is copied from the Get-ServiceNowRequest function. The only real difference is the table it queries. I copied and pasted a simple test for this function from the Get-ServiceNowRequest function, but I can't access the test environment it's querying in order to validate that the test works.
1 parent 1e2287a commit 30991c0

File tree

3 files changed

+98
-1
lines changed

3 files changed

+98
-1
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
function Get-ServiceNowRequestItem {
2+
param(
3+
# Machine name of the field to order by
4+
[parameter(mandatory = $false)]
5+
[parameter(ParameterSetName = 'SpecifyConnectionFields')]
6+
[parameter(ParameterSetName = 'UseConnectionObject')]
7+
[parameter(ParameterSetName = 'SetGlobalAuth')]
8+
[string]$OrderBy = 'opened_at',
9+
10+
# Direction of ordering (Desc/Asc)
11+
[parameter(mandatory = $false)]
12+
[parameter(ParameterSetName = 'SpecifyConnectionFields')]
13+
[parameter(ParameterSetName = 'UseConnectionObject')]
14+
[parameter(ParameterSetName = 'SetGlobalAuth')]
15+
[ValidateSet("Desc", "Asc")]
16+
[string]$OrderDirection = 'Desc',
17+
18+
# Maximum number of records to return
19+
[parameter(mandatory = $false)]
20+
[parameter(ParameterSetName = 'SpecifyConnectionFields')]
21+
[parameter(ParameterSetName = 'UseConnectionObject')]
22+
[parameter(ParameterSetName = 'SetGlobalAuth')]
23+
[int]$Limit = 10,
24+
25+
# Hashtable containing machine field names and values returned must match exactly (will be combined with AND)
26+
[parameter(mandatory = $false)]
27+
[parameter(ParameterSetName = 'SpecifyConnectionFields')]
28+
[parameter(ParameterSetName = 'UseConnectionObject')]
29+
[parameter(ParameterSetName = 'SetGlobalAuth')]
30+
[hashtable]$MatchExact = @{},
31+
32+
# Hashtable containing machine field names and values returned rows must contain (will be combined with AND)
33+
[parameter(mandatory = $false)]
34+
[parameter(ParameterSetName = 'SpecifyConnectionFields')]
35+
[parameter(ParameterSetName = 'UseConnectionObject')]
36+
[parameter(ParameterSetName = 'SetGlobalAuth')]
37+
[hashtable]$MatchContains = @{},
38+
39+
# Whether or not to show human readable display values instead of machine values
40+
[parameter(mandatory = $false)]
41+
[parameter(ParameterSetName = 'SpecifyConnectionFields')]
42+
[parameter(ParameterSetName = 'UseConnectionObject')]
43+
[parameter(ParameterSetName = 'SetGlobalAuth')]
44+
[ValidateSet("true", "false", "all")]
45+
[string]$DisplayValues = 'true',
46+
47+
[Parameter(ParameterSetName = 'SpecifyConnectionFields', Mandatory = $True)]
48+
[ValidateNotNullOrEmpty()]
49+
[PSCredential]
50+
$ServiceNowCredential,
51+
52+
[Parameter(ParameterSetName = 'SpecifyConnectionFields', Mandatory = $True)]
53+
[ValidateNotNullOrEmpty()]
54+
[string]
55+
$ServiceNowURL,
56+
57+
[Parameter(ParameterSetName = 'UseConnectionObject', Mandatory = $True)]
58+
[ValidateNotNullOrEmpty()]
59+
[Hashtable]
60+
$Connection
61+
)
62+
63+
# Query Splat
64+
$newServiceNowQuerySplat = @{
65+
OrderBy = $OrderBy
66+
MatchExact = $MatchExact
67+
OrderDirection = $OrderDirection
68+
MatchContains = $MatchContains
69+
}
70+
$Query = New-ServiceNowQuery @newServiceNowQuerySplat
71+
72+
# Table Splat
73+
$getServiceNowTableSplat = @{
74+
Table = 'sc_req_item'
75+
Query = $Query
76+
Limit = $Limit
77+
DisplayValues = $DisplayValues
78+
}
79+
80+
# Update the Table Splat if the parameters have values
81+
if ($null -ne $PSBoundParameters.Connection) {
82+
$getServiceNowTableSplat.Add('Connection', $Connection)
83+
}
84+
elseif ($null -ne $PSBoundParameters.ServiceNowCredential -and $null -ne $PSBoundParameters.ServiceNowURL) {
85+
$getServiceNowTableSplat.Add('ServiceNowCredential', $ServiceNowCredential)
86+
$getServiceNowTableSplat.Add('ServiceNowURL', $ServiceNowURL)
87+
}
88+
89+
# Perform query and return each object in the format.ps1xml format
90+
$Result = Get-ServiceNowTable @getServiceNowTableSplat
91+
$Result | ForEach-Object {$_.PSObject.TypeNames.Insert(0, "ServiceNow.Request")}
92+
$Result
93+
}

ServiceNow/ServiceNow.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ FormatsToProcess = @('ServiceNow.format.ps1xml')
6666
NestedModules = @()
6767

6868
# Functions to export from this module
69-
FunctionsToExport = @('Get-ServiceNowChangeRequest','Get-ServiceNowConfigurationItem','Get-ServiceNowIncident','Get-ServiceNowRequest','Get-ServiceNowTable','Get-ServiceNowTableEntry','Get-ServiceNowUser','Get-ServiceNowUserGroup','New-ServiceNowIncident','New-ServiceNowQuery','New-ServiceNowTableEntry','Remove-ServiceNowAuth','Remove-ServiceNowTableEntry','Set-ServiceNowAuth','Test-ServiceNowAuthIsSet','Update-ServiceNowChangeRequest','Update-ServiceNowIncident','Update-ServiceNowNumber','Update-ServiceNowTableEntry')
69+
FunctionsToExport = @('Get-ServiceNowChangeRequest','Get-ServiceNowConfigurationItem','Get-ServiceNowIncident','Get-ServiceNowRequest','Get-ServiceNowRequestItem','Get-ServiceNowTable','Get-ServiceNowTableEntry','Get-ServiceNowUser','Get-ServiceNowUserGroup','New-ServiceNowIncident','New-ServiceNowQuery','New-ServiceNowTableEntry','Remove-ServiceNowAuth','Remove-ServiceNowTableEntry','Set-ServiceNowAuth','Test-ServiceNowAuthIsSet','Update-ServiceNowChangeRequest','Update-ServiceNowIncident','Update-ServiceNowNumber','Update-ServiceNowTableEntry')
7070

7171
# List of all modules packaged with this module
7272
# ModuleList = @()

Tests/ServiceNow.Tests.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ Describe "ServiceNow-Module" {
7979
([array](Get-ServiceNowRequest)).count -gt 0 | Should -Match $true
8080
}
8181

82+
It "Get-ServiceNowRequestItem returns records" {
83+
([array](Get-ServiceNowRequestItem)).count -gt 0 | Should -Match $true
84+
}
85+
8286
It "Get-ServiceNowUserGroup works" {
8387
(Get-ServiceNowUserGroup).Count -gt 0 | Should -Match $true
8488
}

0 commit comments

Comments
 (0)