JiraPS
JiraPS copied to clipboard
Populating CustomFields with PSCustomObject
Expected Behavior
Set-JiraIssue -Issue '<issue#>' -Fields $Field
Where $Field is:
$Field = Get-JiraIssue -Key '<otherIssue#>' | select <customfield_11202>
Current Behavior
Above results in:
Set-JiraIssue : Cannot process argument transformation on parameter 'Fields'. Cannot convert value "@{customfield_11202=}" to type "System.Collections.Hashtable". Error: "Cannot convert the "@{customfield_11202=}" value of type
"Selected.System.Management.Automation.PSCustomObject" to type "System.Collections.Hashtable"."
Possible Solution
Function for in-line or on the fly conversion of PSCustomObject to Hashtable
Context
Your Environment
Version
-------
2.1.0.14
Name Value
---- -----
PSVersion 5.0.10586.117
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.10586.117
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
After investigating this for a bit, I have the following findings:
- according to documentations, it should be able for a custom object to convert to string and the hashtable to parse the string: doesn't work for our case
- When casting, several
op_Explicitandop_Implicitcasts happen: I couldn't find any that we could implement - I would have thought, that a method
.Tohashtable()would help: It doesn't [Hashtable]can be casted to[PSCustomObject]: but not the other way around, as we need it
However, finding 4. can be used to change the type definition of the -Fields parameter.
Here is a POC:

@tehfonz : I removed the label up-for-grabs hoping you will tackle this ;-)
If this is not the case, let me know so I can add it again