Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use an array for input to customfields #27

Open
sdaaish opened this issue May 28, 2019 · 4 comments
Open

Use an array for input to customfields #27

sdaaish opened this issue May 28, 2019 · 4 comments
Labels
Needs research Further information is requested or has to be investigated

Comments

@sdaaish
Copy link

sdaaish commented May 28, 2019

How do I enter an array to the input data for customfields? I tried different versions, but I had no success so far.

Set-Jissue -key ITDR-152 -customField @{"Responsible Team" = @("System (CMDB-3605)")} -Verbose
VERBOSE: ParameterSetName [IssueID]
VERBOSE: Updating issue
VERBOSE: Saving [ITDR-152]
DEBUG: Processing [1] running queries
DEBUG: Waiting for an async result to finish
Set-Jissue : System.InvalidOperationException with Saving [ITDR-152]: [data was not an array]
At line:1 char:1
+ Set-Jissue -key ITDR-152 -customField @{"Responsible Team" = @("s ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [Set-JIssue], JiraInvalidActionException
+ FullyQualifiedErrorId : JiraModule.JiraInvalidActionException,JiraModule.SetIssue

This is for an Insight object.
When I get the issue, it looks like this:

 (Get-JIssue -Key itdr-152).customfields| ? name -like responsible*
DEBUG: Queueing running queries
DEBUG: Processing [1] running queries
DEBUG: Waiting for an async result to finish

Values                   Id                Name
------                   --                ----
{system (CMDB-3605)} customfield_11302 Responsible Team
@sdaaish
Copy link
Author

sdaaish commented May 28, 2019

And to clarify, this is the documentation for Insight and customfields: https://documentation.riada.io/display/ICV50/Insight+with+JIRA+REST-API

I finally succeeded updating an issue with JiraPS-module but I would like to stick with your module if possible.

@KevinMarquette
Copy link
Owner

I am sure the issue is here because I was assuming every value should be a string:

issue[key] = CustomField[key]?.ToString();

I will need to set up an example and play with it.

You may be able to work with the issue object directly for this.

$issue = Get-JIssue -Key $Key
$issue["Responsible Team"] = @("System (CMDB-3605)")
$issue | Save-JIssue

If I can't do direct assignment like that, there is also another method that I may look at

$issue.CustomFields.AddById("customfield_90210",@("System (CMDB-3605)"))

Anyway, the $issue object is very rich and full of options that comes directly from the SDK calls. If you find a clean way to do this before I get to it, feel free to share your results.

@sdaaish
Copy link
Author

sdaaish commented May 29, 2019

The first part don't work, there is no customfield with that name when you read from Jira. I can read the customfied by ID but not by name.

With the second part I can set the value, but still get the "Array" issue.

> $issue = Get-JIssue -Key ITDR-150

> $issue["Environment"]

Value
-----
Production

> $issue["Responsible Team"]

<empty>

> $issue.customfields.addbyid("customfield_11302", @("CMDB-24"))

Values             Id                Name
------             --                ----
{Production}       customfield_11304 Environment
{CMDB-24}          customfield_11302 Responsible Team

> $issue|Save-JIssue
Save-JIssue : System.InvalidOperationException with Save issue [ITDR-150]: [data was not an array]
At line:1 char:6
+ $issue|Save-JIssue
+      ~~~~~~~~~~~
+ CategoryInfo          : WriteError: (:) [Save-JIssue], JiraInvalidActionException
+ FullyQualifiedErrorId : Save issue [ITDR-150],JiraModule.SaveIssue

For reference, with JiraPS this is how I can do this as an example:

$fields = @{
    labels = @("Network", "Security")
    customfield_11302 = @(@{ key = "CMDB-8324"})
    customfield_11808 = @(@{ key = "CMDB-24"})
}
Set-JiraIssue -Issue ITDR-154 -Fields $fields

Finding out the syntax for this took me days.

I tried something similar with your module but it didn't work.

>  $issue.customfields.addbyid("customfield_11808", @(@{"key" = "CMDB-3605"}))

Values                         Id                Name
------                         --                ----
{System.Collections.Hashtable} customfield_11808 Function

Save-JIssue : System.InvalidOperationException with Save issue [ITDR-150]: [data was not an array] [data was not an array]
At line:1 char:6
+ $issue|Save-JIssue
+      ~~~~~~~~~~~
+ CategoryInfo          : WriteError: (:) [Save-JIssue], JiraInvalidActionException
+ FullyQualifiedErrorId : Save issue [ITDR-150],JiraModule.SaveIssue

Or this:

> $issue.customfields.addbyid("customfield_11808", @(@("CMDB-3605")))

Values             Id                Name
------             --                ----
{Production}       customfield_11304 Environment
{CMDB-3605}        customfield_11808 Function

> $issue|Save-JIssue
Save-JIssue : System.InvalidOperationException with Save issue [ITDR-150]: [data was not an array]
At line:1 char:6
+ $issue|Save-JIssue
+      ~~~~~~~~~~~
+ CategoryInfo          : WriteError: (:) [Save-JIssue], JiraInvalidActionException
+ FullyQualifiedErrorId : Save issue [ITDR-150],JiraModule.SaveIssue

I have a working method now with JiraPS, so this is for your information. As the say at JiraPS:

Jira has fields of all possible types. Strings, text boxes, numbers, dropdown menus, lists, aso.

@KevinMarquette
Copy link
Owner

Thank you for testing that out. I'll have to dig into the SDK source then to see if it is even supported. or even what is really supported.

@KevinMarquette KevinMarquette added the Needs research Further information is requested or has to be investigated label May 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs research Further information is requested or has to be investigated
Projects
None yet
Development

No branches or pull requests

2 participants