Script to copy system and custom fields when a link is duplicates

Suresh Bhandiwad October 22, 2019

Hello Team,

We have a requirement to copy fields when a link is created which includes System and Custom field fields. We have "Automation for Jira", however it uses common user which doesn't track the who has done the changes.

Environment: Jira Cloud
Add-On: Script Runner for Jira Cloud

Can anyone help me with the sample script, that would be helpful and appreciated. I am beginner, I tried on my own referring existing sample scripts with no success.

Requirements:

When related record type is Duplicates and Initiating Dept = PSO CII and SFDC ID is not null then copy changes to current record to all children of type = Duplicates.

Conditions:
Initiating Dept: Single select custom field
SFDC ID: Single line text field
Issue Type: CII

Fields to be copied: Status, Priority, Assignee, Desc etc

I referred few scripts, They say specify issuekey: Does this mean happen only for specified key?

{code:title=Bar.java|borderStyle=solid}

if (issueLink.issueLinkType.name == "Duplicate"){

def sourceIssueResponse = get("/rest/api/2/issue/${issueLink.sourceIssueId}").asObject(Map)
assert sourceIssueResponse.status == 200
def sourceIssueKey = sourceIssueResponse.body.key

def destinationIssueResponse = get("/rest/api/2/issue/${issueLink.destinationIssueId}").asObject(Map)
assert destinationIssueResponse.status == 200
def destinationIssueKey = destinationIssueResponse.body.key

def parentissue = get('/rest/api/2/issue/' + sourceIssueKey)
.header('Content-Type', 'application/json')
.asObject(Map)
.body


def parentPriority = parentissue.fields.priority.name


def updateissue = put('/rest/api/2/issue/' + destinationIssueKey)
.header('Content-Type', 'application/json')
.body([
fields:[
priority : parentPriority
]
])
.asString()

}

 

{code}

All looks fine, update isn't working fine, please help me

1 answer

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 24, 2019

Hi Suresh,

Thank you for your question.

I can advise that the best way to run your script would be to run the script as a Script Listiner which is configured to fire on the Issuelink Creted  event.

I would then advise that you click on the link named Show Me  next to the text which says There are parameters/variables that are automatically available for use within your script: in the Script Context dialog above the code box, in order to check if all the properties that you are accessing in your script without making a rest call to get them exist in the context of the script.

Also, I would advise checking the logs page as described here in order to check what happeneded during the execution of your script in order to identify why it did not execute as expected.

Regards,

Kristian

Suggest an answer

Log in or Sign up to answer