Closed Adamvg closed 4 years ago
@Adamvg - Hashtable key order can be a bit unpredictable and aren't guaranteed, what you're looking for is an Ordered Dictionary.
Try adding the [ordered]
type cast before the opening of your hashtable:
$FilteredHashTable = [ordered]@{
ID = $ItemHash.boxId
'Total Stock' = $ItemHash.'Total Stock'
Category = $ItemHash.categoryFriendlyName
'Sell Price' = '£' + $ItemHash.sellPrice
'Voucher Buy-in' = '£' + $ItemHash.exchangePrice
'Cash Buy-in' = '£' + $ItemHash.cashPrice
}
New-PoshBotCardResponse -Title $ItemHash.boxName -Fields $FilteredHashTable -LinkUrl ("https://uk.webuy.com/product-detail?id=" + $ItemHash.boxId)
Key order for Fields
on New-PoshBotCardResponse
only works with ordered dictionaries AND only with commands from the builtin
plugin. This is because the commands from builtin are NOT executed as PS jobs like user plugins are. PoshBot will receive the object that New-PoshBotCardResponse
creates in it's native form. With user plugins, the commands are executed in a separate PS job and any output objects will have been deserialized and PowerShell currently doesn't respect key order on deserialized ordered dictionaries. See https://github.com/PowerShell/PowerShell/issues/2861
The order of the items in the Discord card are not following the HashTable order.
Expected Behavior
Should follow the HashTable order.
Current Behavior
Not following the HashTable order.
Possible Solution
Add "-Order HashTable" or something? Custom object to set 1234 etc?
Steps to Reproduce (for bugs)
Context
Unable to order the items in a discord card. Cannot seem to find a specific order it usually goes into.
To clarify, the way I would like is...
Your Environment