Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Jira Cloud Scriptrunner link issue on create

Alex Piwowar October 4, 2018

Im working on a Jira workflow post function that creates an issue. Im trying to add an update so that when it creates the new issue it also links it to the original issue.

When I run it this error keeps coming back

CorrelationId: 222dcd7a-b781-45f8-982d-da4dc4196fdd RUN Script identifier: a1fdfe6b-47f6-49c2-bb94-26a7a9014c0f com.adaptavist.sr.cloud.workflow.RunScript ('Off-Board' transition made for issue HR-460) Took: 3500ms Logs: 2018-10-04 17:52:54.886 WARN - POST request to /rest/api/2/issue returned an error code: status: 400 - Bad Request body: {"errorMessages":["Can not deserialize instance of java.util.ArrayList out of START_OBJECT token\n at [Source: com.atlassian.plugin.connect.plugin.auth.scope.InputConsumingHttpServletRequest$1@1e96084e; line: 1, column: 151] (through reference chain: com.atlassian.jira.rest.v2.issue.IssueUpdateBean[\"update\"])"]} 2018-10-04 17:52:54.928 INFO - POST /rest/api/2/issue asString Request Duration: 1902ms 2018-10-04 17:52:54.929 INFO - Run script completed

 

This is the code im running

def sourceSummary = issue.fields.summary
def exitDate = issue.fields.customfield_13200
def sourceKey = issue.key


post("/rest/api/2/issue") 
.header("Content-Type", "application/json")
.body(
    [
            fields: 
            [
                    "summary"    : sourceSummary,
                    "customfield_13200" : exitDate,
                    "security" : [ "id" : "10101"],

                    "project"    : [
                            "id": "10001"
                    ],
                    "issuetype"  : [
                            "id": "12550"
                    ]
            ],
            "update":[
                "issuelinks":
                [
                    "add":[
                        "type":[
                            "name":"Relates",
                            "inward":"relates to",
                            "outward":"relates to"
                        ],
                        "outwardIssue":[
                            "key":sourceKey
                        ]
                    ]
                ]
            ]
    ])
.asString()

 Im pretty new to this and from other posts Ive seen this should work. Any pointers would be appreciated.

2 answers

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 10, 2018

Hi Alexander,

This error is a static type checking warning which indicates that the script does not understand the issue key and this may be due to the fact that you specified this before the post function which creates the issue meaning it may not be able to understand the issue key.

Could you please try using the example which I shared previosuly as this has been tested and contains no static type checking errors.

This example will create a new issue and link to it and is the recommend approach which we recomend using.

Could you please try the example we provided and if it solves your requirement accept this answer to mark it as correct for other users searching for a similar solution.

Regards,

Kristian

Alex Piwowar October 10, 2018

i see, the issue was that I didnt do .asObject(Map) for the create issue post.

The logs also threw an error about the outwardIssue not having a key so I changed id to key and it worked.

 

Thanks for the help!!!

 

where can I find more resources about what things like .asobject() or .asString() do? 

Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 10, 2018

Hi Alexander,

Thankyou for confirming that your issue has been resolved .

I would suggest that you use the documentation site and the Jira cloud rest API site as help references to learn what APIs to use.

You may also find looking for an online groovy programming useful as this will teach you the groovy language which ScriptRunner uses.

Regards

Kristian

0 votes
Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 8, 2018

Hi Alexandar,

Thank you for your question.

Can I please ask if you are trying to clone an issue and link the cloned issue to the   original issue during a workflow transition?

If this is the case then we provide a built in workflow postfunction inside of ScriptRunner for Jira Cloud called Clone Issue which is described inside of the documentation page located here.

We would recomend using this built in post function to achieve your requirement as you will be able to add it to the transition in the workflow where you need to clone the issue and will be able to conigure its form to specify the issue link type that should be used to link the issues.

Using the built in function will mean that it will be maintained as the Atlassian API changes meaning that it will continue to work when the API Changes and will not require yourself to make any manual script changes.

We also provide example scripts of how to update and how to link and issue inside the Run Script post function which are shown below the code box next to the examples link and you will be able to use the examples to see how to update and issue and to link an issue together using code in order to help you to write a custom script if you require one. 

If this response has answered your question can you please mark it as accepted so that other users can see it is correct when searching for similar answers.

Regards,

Kristian

Alex Piwowar October 8, 2018

Hi Kristian,

I do not wish to clone the issue. I wish to create a new issue that only contains certain fields from the original issue. I am able to successfully create a new issue and copy the fields I want. The problem is that I cannot create the issue links.

Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 8, 2018

Hi Alexander,

Can you please try looking at the example code which we have which shows how to create issue links and use this code inside of your script to create the issue links.

You can access this example code by adding in a Run Script post function and clicking the examples link below the code box and then the Link Issue link which populate the code box with example code on how to link two issues together.

You will then be able to take this code and add into your script and to modify it to link the issues together.

Regards,

Kristian

Alex Piwowar October 9, 2018

I see the example. Is it not possible to create the link under this post command?

post("/rest/api/2/issue") 

 Im creating a new issue so I have the outward issue id but I dont have the id or key for the new issue I just created.

Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 10, 2018

Hi Alexander,

 

Unfortunately you cannot create the link under the same command as you will need to get the issue key for the created issue after the post command has completed and you will need to call the rest API below in order to create an issue link. 

/rest/api/2/issueLink

I have created a sample post function script which you can view here, which shows how to create an issue and then link the newly created issue to the issue which triggered the post function. 

You will be able to take this example post function and update this to achieve your requirement.

If this response has answered your question can you please mark it as accepted so that other users can see it is correct when searching for similar answers.

Regards,

Kristian

Alex Piwowar October 10, 2018

I see that makes sense.

 

For some reason when I try to do

def createdIssueKey = createIssue.body.key

I get the attached error.

 

Screen Shot 2018-10-10 at 10.02.06 AM.png

TAGS
AUG Leaders

Atlassian Community Events