JiraPS icon indicating copy to clipboard operation
JiraPS copied to clipboard

Populating CustomFields with PSCustomObject

Open tehfonz opened this issue 8 years ago • 2 comments

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

tehfonz avatar Jun 30 '17 06:06 tehfonz

After investigating this for a bit, I have the following findings:

  1. 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
  2. When casting, several op_Explicit and op_Implicit casts happen: I couldn't find any that we could implement
  3. I would have thought, that a method .Tohashtable() would help: It doesn't
  4. [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: image

lipkau avatar Jun 30 '17 08:06 lipkau

@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

lipkau avatar Jun 30 '17 08:06 lipkau