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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

ScriptRunner - Adding Ticket ID to attached attachment(s)

Michael
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Oct 18, 2023

Hi everyone,

I'm trying to figure out how to use the Custom script scriptrunner post-function to look for attachements within the create screen, and after the issue is created, add the Jira ticket ID to the front of the attachement(s) name(s).

So far I have this:

import org.ofbiz.core.entity.GenericValue

import com.atlassian.jira.ofbiz.OfBizDelegator

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.attachment.Attachment


def attachmentManager = ComponentAccessor.getAttachmentManager()

OfBizDelegator delegator = ComponentAccessor.getComponentOfType(OfBizDelegator.class)

issue.get("attachment")?.each {

  for(GenericValue attachment : delegator.findByField("FileAttachment", "id", it.id)){

      attachment.setString("filename", issue.summary+it.filename)

      attachment.store()

  }

}

but I can't seem to get this to work. Can anyone help with this?

Thanks,

Mike

2 answers

1 accepted

0 votes
Answer accepted
Michael
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Oct 19, 2023

Hi all,

We figured out how to re-name / pre-append a Jira Ticket ID to all attachments that are added at the create step via the code below. Hope this helps someone else out.

 

import org.ofbiz.core.entity.GenericValue;

import com.atlassian.jira.ofbiz.OfBizDelegator;

import com.atlassian.jira.component.ComponentAccessor;

import com.atlassian.jira.issue.attachment.Attachment;

//def attachmentManager = ComponentAccessor.getAttachmentManager();

OfBizDelegator delegator = ComponentAccessor.getComponentOfType(OfBizDelegator.class)

def issueID = issue.key

issue.getAttachments()?.each {

  for(GenericValue attachment : delegator.findByField("FileAttachment", "id", it.id)) {

    // if filename does not start with ticket key add it

    if (!it.filename.startsWith(issueID)) {

      attachment.setString("filename", "${issueID}_${it.filename}")

      attachment.store()

    }

  }

}
0 votes
Ram Kumar Aravindakshan _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.
Oct 19, 2023

Hi @Michael

From your description, it appears you are trying to rename the attachment name as they are added to the issue. Please confirm.

I am asking this so I can try to provide with a sample solution.

Thank you and Kind regards,
Ram

Suggest an answer

Log in or Sign up to answer