Incomplete results returned with IncludeCustomVariable
shimonek opened this issue · 4 comments
Environment
Operating System: Server 2012 R2, Server 2016
ServiceNow module version: 3.1.3, 2.4.1
PowerShell version: 5.1.14393.4583, 5.1.14409.1018
Steps to reproduce
Get-ServiceNowRecord -Table 'Requested Item' -IncludeCustomVariable -Filter @('number', '-eq', 'RITM0124161') | select -exp CustomVariable
Expected behavior
Should return Name, DisplayName and Value columns populated with custom variable information.
Actual behavior
Returns Name and DisplayName columns but the Value column is blank.
I am able to retrieve variable information using this function:
function Get-RITMVariables {
param ([String] $RITM)
$variables = @()
$options = Get-ServiceNowRecord -Table sc_item_option_mtom -Filter @('request_item', '-like', $RITM) -IncludeTotalCount
try {
foreach ($option in $options) {
$sys_id = $option | Select-Object -ExpandProperty sc_item_option | Select-Object -ExpandProperty display_value
$itemOption = Get-ServiceNowRecord -Table sc_item_option -Filter @('sys_id', '-eq', $sys_id)
if ($itemOption.item_option_new -match '^.+\/item_option_new\/(?<ion>.+)}$') {
$itemOptionNew = Get-ServiceNowRecord -Table item_option_new -Filter @('sys_id', '-eq', $($matches.ion))
$variables += [PSCustomObject] @{
name = $itemOptionNew.name
type = $itemOptionNew.type
question = $itemOptionNew.question_text
value = $itemOption.value
}
}
}
New-LogEntry -Ticket $RITM -Function 'Get-RITMVariables' -Entry "Found $($variables.Count) variables"
} catch {
New-LogEntry -Ticket $RITM -Function 'Get-RITMVariables' -Entry "Failed retrieving variables"
New-LogEntry -Ticket $RITM -Entry $Error[0].Exception -Error
}
Return $variables
}
Screenshots
Btw, you can just use Get-ServiceNowRecord RITM0124161 -IncludeCustomVariable
. No need to specify the filter or table.
All of the fields are missing values. Thanks @gdbarron.
Get-ServiceNowRecord RITM0124161 -IncludeCustomVariable | select -exp customvariable
Name DisplayName Value
variables.SLT_EOB_phoneext Phone Extension (if available)
variables.SB_EOB_region Region?
variables.SLT_EOB_alttitle Role/Title in Offer Letter?
variables.SB_EOB_AVRD Azure Virtual Desktop required
variables.SLT_EOB_firstname First Name
variables.REF_EOB_TCGROUP Local ITSS Group
variables.SLT_EOB_lastname Last Name?
variables.SLT_EOB_middleinitial Middle Initial?
variables.MLT_EOB_Addinfo Use this space to add any additional information re: special rights/priveleges/role
variables.REF_EO_location Physical Location?
variables.D_EOB_CampDate Camp Session
variables.SB_EOB_jobtype Job Type:
variables.REF_EOB_HRC HR Contact
variables.SLT_EOB_title Level/Title?
variables.SLT_EOB_dept Department?
variables.SLT_EOB_username AD username (if available)
variables.SLT_EOB_preferredname Preferred Name (re-enter First Name if blank on notification)
variables.MC_EOB_phonetype Phone Type
variables.REF_EOB_ITSS_orient REF_EOB_ITSS_orient
variables.REF_EOB_manager Hiring Manager
variables.SLT_EOB_empID Candidate ID?
variables.SB_EOB_active Currently Active Employee?
variables.SB_EOB_camptrack Camp Track
variables.MLT_EOB_ITSetupNotes IT Setup Notes
variables.SLT_EOB_country Country
variables.SLT_EOB_HRCemail HR Contact email
variables.SLT_EOB_phoneDID Direct Dial number (if available)
variables.SLT_EOB_HireType Hire Type?
variables.REF_EO_PU Office?
variables.D_EOB_start_date Start Date