Forums

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

Copy Creator (system field) to custom field text using scriptrunner

Alvin
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.
October 18, 2018

Hi All, how is it possible to copy creator system field to a string , custom field text using scriptrunner upon creation. using behavior? using listener? postfunctions? please help

1 answer

1 accepted

2 votes
Answer accepted
Andrew
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.
October 18, 2018

Do You want save creator for log? JIRA issue has 'History' tab and there saved who created.

Alvin
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.
October 18, 2018

Hi @Andrew . I want to copy the Creator (system field) to a custom field text to display the copy of creator to view screen

Andrew
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.
October 18, 2018

I made it with postfunc, it work for me.

  1. Go to workflow, select transition 'Create'
  2. Add PF
  3. Select Script Post-Function [ScriptRunner]
  4. Insert code
  5. Publish workflow

My example:

import com.atlassian.jira.component.ComponentAccessor
def reporter = issue.reporter.name
def cfm = ComponentAccessor.getCustomFieldManager()
def cfMy = cfm.getCustomFieldObjectByName("myfield")
issue.setCustomFieldValue(cfMy,reporter)

Andrew
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.
October 18, 2018

Use postfunction it work for me.

  1. Edit workflow
  2. select transition 'Create'
  3. Add postfunction
  4. Select 'Script Post-Function [ScriptRunner]'
  5. Add code
  6. Publish workflow

Example code:

import com.atlassian.jira.component.ComponentAccessor
def reporter = issue.reporter.name
def cfm = ComponentAccessor.getCustomFieldManager()
def cfMy = cfm.getCustomFieldObjectByName("myfield")
issue.setCustomFieldValue(cfMy,reporter)

Alvin
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.
October 18, 2018

Hi @Andrew, I edited the code to make it suit for creator because that is what I need

issue.creator.name

thank you for that . but it returns this error

Screenshot from 2018-10-18 23_06_17.png

Andrew
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.
October 18, 2018

Try it:

...
def reporter = "my test value"
...

if work try next:

...

def reporter = issue.get("reporter").getUsername()

...

Alvin
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.
October 18, 2018

Hi @Andrew , thanks for helping, what do you mean by "my test value"

Andrew
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.
October 18, 2018

Just string. After create issue You should get "my test value" in your field.  For checking of part script which SET value.

...
def reporter = "some your string :-)"
...

Alvin
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.
October 18, 2018

Hi @Andrew , where should I put the post function? at the very beginning?

Alvin
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.
October 18, 2018

Here is my sample code, it does not populate the some string to sample custom field, which is a text field

 

import com.atlassian.jira.component.ComponentAccessor
def creator = "some string"
log.error("kdflkdfk $creator")
def cfm = ComponentAccessor.getCustomFieldManager()
def cfMy = cfm.getCustomFieldObjectByName("Sample")
issue.setCustomFieldValue(cfMy,creator)

Andrew
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.
October 18, 2018

If You want set value after creating issue:jirawf.png

Alvin
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.
October 18, 2018

@Andrew , yes I have done that one, but it does not set the value after creating the issu

Alvin
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.
October 18, 2018

I have put the code there. on post functions

Andrew
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.
October 18, 2018

Some log error? 

Name of field "Sample"? Try
def cfMy = cfm.getCustomFieldObject("<set ID number>")

<set ID number> you can get here:asdf.png

Alvin
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.
October 18, 2018

Hi @Andrew, thank you, the thing that made this discussion go long is that because I did not publish the workflow, cheers bud. thanks for the help. answer accepted.

Alvin
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.
October 18, 2018

Hope you help many more questions in this community. Cheers!

Suggest an answer

Log in or Sign up to answer