Modify an actual issue field

Hi,

I'm trying to modify programmatically an issue field using the code i found here "https://developer.atlassian.com/download/attachments/5670239/JIRADEV-310811-0110-8.pdf" in the 145 page. I'm using JIRA 4.1.2, and that's my listener:

**************

public void workflowEvent(IssueEvent event){

IssueInputParameters iip = new IssueInputParametersImpl();
iip.setSummary("I am a new summary");
IssueService is = ComponentManager.getInstance().getIssueService();
UpdateValidationResult updateValidationResult = is.validateUpdate(event.getRemoteUser(), event.getIssue().getId(), iip);
if (updateValidationResult.isValid())
{
IssueResult updateResult = is.update(event.getRemoteUser(), updateValidationResult);
if (!updateResult.isValid()){}
}

}

**************

There's no warnings or errors on the JIRA console, but my summary doesn't change to "I am a new summary". So, how can i change the fields of my actual issue programmatically?

I've been looking the forum and i tryed this (https://answers.atlassian.com/questions/40245/how-do-i-save-a-custom-field-description-in-the-jira-data-base) too:

**************

ComponentManager.getInstance().getIssueFactory().getIssue().setSummary("I am a new summary");
ComponentManager.getInstance().getIssueFactory().getIssue().store();

**************
and this too:

**************

final IssueService.IssueResult issueResult = issueService.getIssue(null, event.getIssue().getKey());
final MutableIssue mutableIssue = issueResult.getIssue();
mutableIssue.setSummary("I am a new summary");
mutableIssue.store();

**************

Any idea. Thanks.

Alberto.

4 answers

Hi again,

As i can't change my issue fields...there's any way to access to JIRA database and change it there? If the answer is "yes" my next question must be..."how?". I've seen the JIRA API and i didn't find any connection to database class.

Regards.

Alberto

0 vote

It's easy to change it in the database. The process is:

  1. Stop Jira
  2. Backup your database
  3. Prove the backup works by restoring it on another server and checking your test Jira can use it
  4. Run the SQL in live
  5. Restart Jira
  6. Reindex it

The whole point of the API and the structure of the code in Jira is that it isolates you from the database (and other system components) and you shouldn't need to think about it. Your listener is going in the right direction (because it's not touching the database), but the code doesn't look quite right to me, because you've only posted fragments of it. For example, your first block of code doesn't mention the issue at all, there's no mention of reindexing (which may be required), etc

0 vote
Mizan Community Champion Jun 10, 2012

You can have a look at the Jira CLI plugin which provides a command to update existing issue ,examples

Hi,

Sounds good Mizan, i'll take a look soon.

Nic, i'm agree with "The whole point of the API and the structure of the code in Jira is that it isolates you from the database"...But sometimes is really frustrating :(

I still been unable to do what i want programmatically without 3rd persons plugins :(

Anyway. i refuse to keep on trying this, i'll try something new using links. I'll make a new post beacouse i'll change the topic. Let's see if i can solve a link problem:

************

IssueLinkManager issueLinkManager = ComponentManager.getInstance().getIssueLinkManager();
try {
issueLinkManager.createIssueLink(event.getIssue().getId(), createResult.getIssue().getId(), 10040L, new Long(0), event.getRemoteUser());
}catch (CreateException e) {e.printStackTrace();}

************

"10040L" and "new Long(0)" are the required issueLinkTypeId and sequence fields. May you know how to get them? I'd tryed this just for test but is giving me a lot of problems.

Thanks both!

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Jira

Meet the AUG leaders of Northern Virginia

@Rachel Wright (Jira Genie), @Billy Poggi (AUG NOVA, DC), and @Dana Jansen (Confluence Queen) are just some of the folks that lead one of the world's most active Atlassian User Group (AUG)....

146 views 5 9
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you