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

Help With Custom Fields #61

Closed
mcornille opened this issue Nov 25, 2016 · 11 comments
Closed

Help With Custom Fields #61

mcornille opened this issue Nov 25, 2016 · 11 comments

Comments

@mcornille
Copy link

Hi,

First of all nice work, this module saves me time.
But i have a question about Set-JiraIssue
I want to update a custom field but this custom field is a dropdown field how do i update this?

field is called "Environment Sx" (customfield_11154)
Possible values: Production, Test, Acceptance, Development
I tried the following commands but that did not work:
Current value of that field is Development or id 14753 and i want to update it to production or id 14750

Set-JiraIssue -Issue $JiraIssue -Fields @{'Environment Sx' = 'Production';}

Set-JiraIssue -Issue $JiraIssue -Fields @{'Customfield_11154' = 'Production';}

Set-JiraIssue -Issue $JiraIssue -Fields @{'Customfield_11154' = '14750';}
14750 = Value Production

But the result of all the commands are the same: WARNING: JIRA returned HTTP error 400 - BadRequest
result

It is possible to get the current value:
$JiraIssue.customfield_11154
returns:
return

Is custom field with dropdown not supported or is my code wrong?

@replicaJunction
Copy link
Collaborator

replicaJunction commented Nov 30, 2016

Take a look at #56 - there's some syntax quirks when your field only allows specific values.

Basically, you'll want something like this:

$field = @{
    'customfield_11154' = @{
        id = '14750' # Production
        # You *might* also be able to do this with value = "Production" instead...not sure on that one
    }
}

Set-JiraIssue -Issue $JiraIssue -Fields $field

This is on my radar as something that needs to be documented better, but I haven't had much time lately.

@lipkau
Copy link
Member

lipkau commented Dec 1, 2016

I created the PR https://github.com/replicaJunction/PSJira/pull/59 exactly for that reason.
I created the Get-JiraissueEditMetadata function, so I can query the allowed values of a field. Then you can get the id of the element with the value you are looking for

@hvikesaa
Copy link

What about a customfield with labels?
Get-JiraField gives this:

ID : customfield_14560
Searchable : True
Schema : @{type=array; items=string; custom=com.atlassian.jira.plugin.system.customfieldtypes:labels; customId=14560}
Name : Model ID
Custom : True
Navigable : True
Orderable : True
ClauseNames : {cf[14560], Model ID}

What I have tried is this:
$field = @{ 'customfield_14560' = @(@{ 'customfield_14560' = 'PROD' }) }

Error is:

Resolve-JiraError : Jira encountered an error: [customfield_14560] - string expected at index 0
At C:\Program Files\WindowsPowerShell\Modules\PSJira\1.2.5.136\Internal\Invoke-JiraMethod.ps1:111 char:13

  •         Resolve-JiraError $result -WriteError
    
  •         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
    • FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Resolve-JiraError

@lipkau
Copy link
Member

lipkau commented Dec 28, 2016

Based on the error description, I would try:
$field = @{ 'customfield_14560' = @('PROD') }

@hvikesaa
Copy link

That worked, thanks!

@hvikesaa
Copy link

Since this worked out so well, I have another one.

From Get-JiraIssueCreateMetadata:

Id : customfield_14662
Name : Server OS
Schema : @{type=option-with-child; custom=com.atlassian.jira.plugin.system.customfieldtypes:cascadingselect; customId=14662}
HasDefaultValue : False
Required : False
AllowedValues : {@{self=https://jira.internal.com/rest/api/2/customFieldOption/20140; value=Windows; id=20140; children=System.Object[]}, @{self=https://jira.internal.com/rest/api/2/customFieldOption/20141; value=Linux; id=20141; children=System.Object[]}, @{self=https://jira.internal.com/rest/api/2/customFieldOption/20143; value=Other; id=20143; children=System.Object[]}}
Operations : set

$field = @{
    'customfield_14662' = @{
        id = '20140'
    }
}

It's no problem setting just the main field, but how to get the allowed values for the child-field, and how to set them?
I can of course see the allowed values in Jira (for Linux the field populates with ie. RHEL, CentOS etc, for Windows it's 2008, 2012...)

@lipkau
Copy link
Member

lipkau commented Dec 28, 2016

What is the metadata for the child fields?

@hvikesaa
Copy link

Where can I find it? It's not a separate custom field.
An Issue that on the web shows both as "Server OS: Windows - 2012 R2" and "Server OS: Windows - 2008 R2", shows like this with Get-JiraIssue:

customfield_14662

@{self=https://jira.internal.com/rest/api/2/customFieldOption/20140; value=Windows; id=20140; child=}

@hvikesaa
Copy link

hvikesaa commented Dec 30, 2016

Using the REST API, I got the following output from that same issue:
image
And with PSjira:
image

Here's what I get when querying for createmeta:
"customfield_14662": {
"required": false,
"schema": {
"type": "option-with-child",
"custom": "com.atlassian.jira.plugin.system.customfieldtypes:cascadingselect",
"customId": 14662
},
"name": "Server OS",
"hasDefaultValue": false,
"operations": [
"set"
],
"allowedValues": [
{
"self": "https://jira.internal/rest/api/2/customFieldOption/20140",
"value": "Windows",
"id": "20140",
"children": [
{
"self": "https://jira.internal/rest/api/2/customFieldOption/20148",
"value": "2000",
"id": "20148"
},
{
"self": "https://jira.internal/rest/api/2/customFieldOption/20144",
"value": "2003",
"id": "20144"
},
{
"self": "https://jira.internal/rest/api/2/customFieldOption/20147",
"value": "2008",
"id": "20147"
},
{
"self": "https://jira.internal/rest/api/2/customFieldOption/20146",
"value": "2008 R2",
"id": "20146"

@replicaJunction
Copy link
Collaborator

Give this a try. I'm guessing a little bit here, but I think this will work:

$field = @{
    'customfield_14662' = @{
        id = '20140'
        child = @{
            value = '2008 R2
        }
    }
}

# Add other params like reporter, priority, etc.
New-JiraIssue -Fields $field

@hvikesaa
Copy link

hvikesaa commented Jan 2, 2017

Works perfect! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants