Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

update customfield in another issue via postfunction

Consulente Atlassian
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.
December 28, 2018

I have a project with two issuetype:
a) activate account
and
b) deactivate account

I use the first issue type to create an account activation request, which is approved. when it is approved I store the value "active" in a customfield called "status account"

when a user of jira wants to deactivate an account, I first do a search to see if I already have the account activated. So I use issue type b) and through a customfield script and a JQL I find all the issue types a) that are with status = approved and customfield status account = active and show them in the list.

then the user chooses only one value from this list. this value corresponds to the issue type a) which is the initial activation request.

I would like to ensure that when the issue type b) (deactivation of accounts) is approved, the custom field "status account" of the issue type a) is updated, which I have selected before, with a new value = inactive. but i do not know how you do this with postfunction and script runner, can anyone help me?

2 answers

1 accepted

0 votes
Answer accepted
Bastian Stehmann
Community Champion
December 28, 2018

Hi @Consulente Atlassian,

Why don't you use just a single issue type and do the status via workflow?

You do not have to do the updates of other issues then and have all information in one place?

Consulente Atlassian
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.
December 28, 2018

@Bastian Stehmann

 

Meanwhile, thank you for your reply. Simple, because I had not thought about it and because I'm now starting to practice so I do not know how to set this configuration that you suggest and I do not want to take advantage of the patience of those like you who is helping me.

Bastian Stehmann
Community Champion
December 28, 2018

You are welcome.

The easiest way to set that up is to simply add the workflow of account deactivation issue type to your other workflow. 

You might need to think if there is some status needed for the transition of one workflow to the other, but in general that is what I meant.

Consulente Atlassian
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.
December 29, 2018

well, thank you for your suggestion
I have already created two workflows, WFA which is linked to the issuetype Active Account and WFB which is connected to the issuetype Deactive Account
so when an account activation request is made, I use WFA and Active Account
when I have to deactivate an account, I propose the issuetype Deactive Account and the WFB.
the problem that I still can not solve and that maybe I have not explained well before is that I have to check before disabling an account, if this account exists already activated
then in WFB, that of disabling account to understand, I use a scripted custom field and scriptrunner that calls a JQL that finds all the issues of type Active Account that have the status "actived"
and presents them to the user to allow them to choose which issue = active account, they want to deactivate.
it is at this point that I do not know how I can "take" the issuekey of the issue chosen by the user and pass it to scriptrunner to say: put the issuekey X in status = deactived. In short, I would like to change the status of the "Acrtive Account" issue chosen by "Actived" to "Deactived". I'm continuing to search with google to see if I can find an example.

Bastian Stehmann
Community Champion
December 29, 2018

Thanks for your explanation. 

What I meant waa, that if you let the users select one of the active accounts and they can set that issue just to the first status of the WFB workflow(and you run through this workflow),  you have everything in this one issue.

Consulente Atlassian
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.
December 29, 2018

yes, I'll explain better, I've already done something similar to what you suggest and it came easy because it was jira's account = users. In this second problem, however, where I wrote "account" I mean more exactly "name of an object" as if it were in a CMDB. It would be enough to understand how to pass the issuekey of an "issue" chosen from a drop-down list, as a parameter to indicate the issue where to find the customfield to modify and I would have solved.up to now I am finding many examples where an issue is indicated directly by writing the key in the scriptrunner code and therefore it does not work for what I want to do.

Bastian Stehmann
Community Champion
December 29, 2018

Ok  so your problem is to get the key as value from your scripted field, right?

Like Consulente Atlassian likes this
Consulente Atlassian
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.
December 30, 2018

right and next to change the status of this issue from "Active" to "Inactive"

 

Bastian Stehmann
Community Champion
December 30, 2018

Did you try to get the value of your scripted field like this?

def value = issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("ScrptedFieldName"))

What is result of this?

For loading the other issue, Please have a look here 

https://community.atlassian.com/t5/Adaptavist-questions/Issue-Manager-getIssueObject-oddity/qaq-p/458910

Like Consulente Atlassian likes this
0 votes
Consulente Atlassian
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.
January 16, 2019

hi @Bastian Stehmann Thank you for your help, in the end I took a cue from your suggestion and I improved other code that I wrote.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.event.type.EventDispatchOption
def log = Logger.getLogger("com.acme.CreateSubtask")
log.setLevel(Level.DEBUG)
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
def statusfield = customFieldManager.getCustomFieldObjectByName('Account');
def issuekey = issue.getCustomFieldValue(statusfield);

log.debug issuekey

MutableIssue Missue = ComponentAccessor.getIssueManager().getIssueByCurrentKey(''+issuekey)
log.debug Missue.key

CustomField cfStatoAccount = customFieldManager.getCustomFieldObjectByName('Status')
log.debug cfStatoAccount.name

Missue.setCustomFieldValue(cfStatoAccount,'Inattivo')
log.debug Missue.getCustomFieldValue(cfStatoAccount)

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
ComponentAccessor.getIssueManager().updateIssue(user, Missue, EventDispatchOption.ISSUE_UPDATED, false)

Suggest an answer

Log in or Sign up to answer