Snow-Shell / servicenow-powershell

PowerShell module to automate ServiceNow service and asset management. This module can be used standalone, with Azure Automation, or Docker.
Apache License 2.0
359 stars 170 forks source link

Custom Variable 'Reference' Type Value is Incorrect #218

Closed RichardMawdsley closed 1 year ago

RichardMawdsley commented 1 year ago

Discussed in https://github.com/Snow-Shell/servicenow-powershell/discussions/217

Originally posted by **RichardMawdsley** December 7, 2022 Hi There, Been using the CustomVariable option on the Get-ServiceNowRecord function for some time and it's working great. However, I'm unsure if I've found a bug or if it's just pulling the wrong information back, but what I'm getting is incorrect when the Type is 'Reference'. ``` $RITM = Get-ServiceNowRecord -ID $SNNumber -IncludeCustomVariable -New $RITM.CustomVariable ``` Returns: ``` @{Value=ddf18f001b217700dfa575d6cc4bcb47; DisplayName=Location; Type=Reference} ``` When if I look in ServiceNow, the actual value is: ``` London - Main Office ``` Same is resulted without '-New' too. Unsure if it's related to the -DisplayValue parameter or this was supposed to resolve this very problem, but seemingly adding it causes the .customvariable to be empty. I assume that what it's pulling is the ID or something of that value, but I'm not a ServiceNow admin so unsure on that. Thanks in advance.
gdbarron commented 1 year ago

Hi @RichardMawdsley. I assume the value being returned is the sysid for 'London - Main Office' in the Location lookup/table. If you can confirm, we can add this as an enhancement. This is expected as reference lookups for the underlying value require dot sourcing, if possible, or another call to the referenced table.

RichardMawdsley commented 1 year ago

Hi @gdbarron , yes had it confirmed that this is the sysid. Much appreciated if this enhancement could be added!

gdbarron commented 1 year ago

@RichardMawdsley the update is in. Would you mind testing?

RichardMawdsley commented 1 year ago

Perfect! Values are now getting returned exactly as expected. Thanks @gdbarron !