It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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

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
Community showcase
Published in Jira

The add-in you’ve been waiting for: Jira Cloud for Excel 🙌

Introducing Jira Cloud for Excel Here at the product integrations team at Atlassian, we are thrilled to announce the new Jira Cloud for Excel add-in! This add-in lets you export Jira data directly ...

888 views 7 24
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you