Forums

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

Field value clear in jira using script runner

Abhishree Nagesh
Contributor
August 25, 2019

Hi,

when the issue is transitioned from one status to another then Field value in transition screen should be get clear.

we have Script Runner.

kindly help with script.

 

Thanks,

Abhishree Nagesh

3 answers

1 vote
Suhas P
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.
August 27, 2019

If you want to clear assignee (which is not a custom field), try following on post function.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

def issueManager = ComponentAccessor.getIssueManager()
issue.setAssignee(null)
issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)



Abhishree Nagesh
Contributor
August 27, 2019

@Suhas P 

we are getting error please find the snapshot for error.

Kindly help.

Regards,

Abhishree Nagesh

new code error.png

Suhas P
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.
August 28, 2019

@Abhishree Nagesh  add following line anywhere before issueManager.updateIssue line 

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
Like Javier Orellana likes this
Abhishree Nagesh
Contributor
August 28, 2019

@Suhas P 

By default jira would take previous value in transition screen(assignee).

But if user didnt change the value of assignee when they do the transition then ticket must automatically assign back to reporter.

How to achive this using script runner

kindly provide solution.

 

Regards,

Abhishree Nagesh

Suhas P
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.
September 4, 2019

Hi @Abhishree Nagesh 

Try this code which should fulfill your needs. I haven't tested it myself though. Let me know if it works.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

def issueManager = ComponentAccessor.getIssueManager()

if(transientVars["issue"].assignee == issue.assignee){

issue.setAssignee(issue.reporter)
issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)

}


Like Javier Orellana likes this
0 votes
Suhas P
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.
August 26, 2019

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

def cfm = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()
def changeHolder = new DefaultIssueChangeHolder()
def cf = cfm.getCustomFieldObject("customfield_XXXX") // CF ID
cf.updateValue(null, it, new ModifiedValue(null, ""), changeHolder)
issueManager.updateIssue(user, issueManager.getIssueObject(it.getKey()), EventDispatchOption.DO_NOT_DISPATCH, false)

 

 

 

@Abhishree Nagesh Try this one on script post function.

0 votes
Sreenivasaraju P
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.
August 25, 2019
Abhishree Nagesh
Contributor
August 27, 2019

Hi @Sreenivasaraju P 

Script  is giving me error.

Actually the field is assignee field.

In every transition screen there is a assignee field. So assignee field value should get clear, when transition happens.(I.e in the transition screen field shoukld not take previous assignee name.)

Its giving me error in the last line. please find the snapshot of the error.

snapshot code error.png

 

Kindly help.

Thanks,

Abhishree

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events