How to put jira issue key into a jira custom field automatically

Sys Admin December 11, 2015

We have a custom field namely "JIRA Issue key" in create issue screen. Now we like to put JIRA issue key into this field automatically after issue creation. Is there any way to do this activity? 

5 answers

2 votes
Nic Brough -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.
December 11, 2015

You need a little bit of code - remove the field from the create screen and find/write a post-function that posts the key into the field instead.

Of course, it's pretty pointless - why don't you just use the key that's already there?

0 votes
Evan Golden December 16, 2015

I was able to simply do a post function and copy field to field using the key.  It works quite simply.  Keep in mind if you resolve the issue, the key will be lined out in the separate custom field.  You will need to take the custom field out of the create screen, and put it only in the view screen instead.

0 votes
Sys Admin December 14, 2015

Hi Zverov, After using this script no error occurred. But "Jira Issue Key" field also not showing in the view issue screen

0 votes
Sys Admin December 11, 2015

Hi Nic,

 

Thank you very much for your reply. It is our client requirement. Could you please inform us the detailed steps what we need to do. It will be very helpful for us then

Nic Brough -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.
December 11, 2015

"I want it" really doesn't answer the question. Why is the client wasting your time with a duplicated and potentially inaccurate field? Have you thought through what happens if the issue moves? That's why I question the requirement - without knowing why they want it and what they plan to do with it, you can NOT usefully define the behaviour or As a side effect, once you know *why* they want a pointless field, you will probably be able to give them a significantly *better* solution than a useless field. If you really do end up having to fulfill a pointless requirement, then the *best* way to do it is 1. Install Script Runner ( https://marketplace.atlassian.com/plugins/com.wittified.jira.project-creator/server/overview ) 2. Use Vasiliy's script above (Yes, point 1 is a bit of an advert as I work for Adaptavist and hence with the Scriptrunner team- there are other add-ons which could do it, but I've always reached for ScriptRunner for all the more complicated stuff, and I'd have posted the same if I didn't work there)

Sys Admin December 11, 2015

Thank you Nic for your explanation. You are absolutely right. We will certainly inform our clients about the side effects you mentioned. But for backup if they ordered us to do so we need to configure this. That is why I am asking this question.

Nic Brough -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.
December 11, 2015

That's why Vasiliy and I are trying to help :-) While the field is utterly useless and probably the symptom of a broken requirement or thought process, and hence I'm recommending that you ask *why*, we know clients can persist with doing dumb things! So we're still giving you the guidance about how to use the field and how to make it happen!

Sys Admin December 11, 2015

Thank you very much both of you.

0 votes
Vasiliy Zverev
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 11, 2015

Try this script for ScriptRunner postfunction:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.UpdateIssueRequest
import com.atlassian.jira.issue.fields.CustomField

/**
 * Script for copy value from one custom field to another
 */

//Prepare to update
UpdateIssueRequest.UpdateIssueRequestBuilder issueRequestBuilder = new UpdateIssueRequest.UpdateIssueRequestBuilder();
issueRequestBuilder.eventDispatchOption(EventDispatchOption.ISSUE_UPDATED);
issueRequestBuilder.sendMail(false);
UpdateIssueRequest updIssReq = new UpdateIssueRequest(issueRequestBuilder);

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField cstFld = customFieldManager.getCustomFieldObjectByName("Name");

if(     (cstFld_From == null)
     {
        issue.setCustomFieldValue(cstFld, issue.getKey())
        issueManager.updateIssue(ComponentAccessor.getJiraAuthenticationContext().getUser(), issue, updIssReq);
}
Sys Admin December 11, 2015

Hi Zverev, Thank you for help. Could you please inform me which type custom field we need to create. Is it "Text Filed" type or "Select List" type or anything else. Do we need to associate this field wth create issue screen?

Nic Brough -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.
December 11, 2015

The code posts a string, so it's a "text" field - I'd use the short one rather than multi-line. You do *not* put it on the create screen - if you did, the user could fill it in and then have your code destroy what they enter. Better not offer it to them or they'll get confused.

Nic Brough -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.
December 11, 2015

Ah, yes, you do *not* want the field on the issue "Create" screen, but you *do* want it on the "View" screen. That's probably why it's not there. Check the view screen (and maybe try the "where's my field" option) for the field. If it is on there, then it might be the script going wrong, but definitely check the screen first.

Sys Admin December 11, 2015

Hi Nic, The field is not there. I am inform you the detailed steps which I have followed - 1. Create a Text Field namely "Jira Issue Key" and do not associate with any screen 2. Select Workflow 2. Click Open Step 3. Click Create 4. Add Post function namely "Script Post-Function" 5. Add below mentioned script in "In line Script" section - import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.event.type.EventDispatchOption import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.IssueManager import com.atlassian.jira.issue.UpdateIssueRequest import com.atlassian.jira.issue.fields.CustomField /** * Script for copy value from one custom field to another */ //Prepare to update UpdateIssueRequest.UpdateIssueRequestBuilder issueRequestBuilder = new UpdateIssueRequest.UpdateIssueRequestBuilder(); issueRequestBuilder.eventDispatchOption(EventDispatchOption.ISSUE_UPDATED); issueRequestBuilder.sendMail(false); UpdateIssueRequest updIssReq = new UpdateIssueRequest(issueRequestBuilder); CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager(); CustomField cstFld = customFieldManager.getCustomFieldObjectByName("Jira Issue Key"); if( (cstFld_From == null) { issue.setCustomFieldValue(cstFld, issue.getKey()) issueManager.updateIssue(ComponentAccessor.getJiraAuthenticationContext().getUser(), issue, updIssReq); } After adding this the post-function order like this - 1. Creates the issue originally. 2. Script workflow function : A custom script will be run: from inline script. 3. Re-index an issue to keep indexes in sync with the database. 4. Fire a Issue Created event that can be processed by the listeners Publish Workflow Now I create a issue. But after issue creation "Jira Issue Key" not showing in the issue screen Please suggest

Vasiliy Zverev
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 11, 2015

Check that this postfunction follows a postfunction that creates an issue. More simple - move this postfunction to the bottom of postfunctions list

Sys Admin December 11, 2015

now i reorder postfunction as below - The following will be processed after the transition occurs 1. Creates the issue originally. 2. Re-index an issue to keep indexes in sync with the database. 3. Fire a Issue Created event that can be processed by the listeners 4. Script workflow function : A custom script will be run: from inline script. i have add this postfunction in create transtion. but still jira issue key field not showing after creating issue

Vasiliy Zverev
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 11, 2015

In oreder to find a problem tou can do: 1) (cstFld_From == null) is incorrect, you need (cstFld_From != null). Namely it means that custon field is found. 2) Analise atlassian-jira.log for errors.

Sys Admin December 12, 2015

hi zverev, thank you again for your help. right now i am using below mentioned script - import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.event.type.EventDispatchOption import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.IssueManager import com.atlassian.jira.issue.UpdateIssueRequest import com.atlassian.jira.issue.fields.CustomField /** * Script for copy value from one custom field to another */ //Prepare to update UpdateIssueRequest.UpdateIssueRequestBuilder issueRequestBuilder = new UpdateIssueRequest.UpdateIssueRequestBuilder(); issueRequestBuilder.eventDispatchOption(EventDispatchOption.ISSUE_UPDATED); issueRequestBuilder.sendMail(false); UpdateIssueRequest updIssReq = new UpdateIssueRequest(issueRequestBuilder); CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager(); CustomField cstFld = customFieldManager.getCustomFieldObjectByName("Jira Issue Key"); if ((cstFld_From != null) { issue.setCustomFieldValue(cstFld, issue.getKey()) issueManager.updateIssue(ComponentAccessor.getJiraAuthenticationContext().getUser(), issue, updIssReq); } i have also check atlassian log. there is a error. please find the error below - unction] Script function failed on issue: SHD-11356, actionId: 1, file: <inline script> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script39.groovy: 26: expecting ')', found '' @ line 26, column 2. } ^ 1 error i like to mention one thing which i observed. i dont whether this is correct or not. in the script 'if' has not closed with 'fi' . also after 'if' there is a '(' has not closed with ') . could you kindly look into this

Vasiliy Zverev
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 12, 2015

You have additional bracket "(" into if statement. if (cstFld_From != null) { issue.setCustomFieldValue(cstFld, issue.getKey()) issueManager.updateIssue(ComponentAccessor.getJiraAuthenticationContext().getUser(), issue, updIssReq); } To speed up development see https://answers.atlassian.com/questions/32982259/answers/32982329?flashId=-1332650553

Sys Admin December 12, 2015

hi zverev, i have remove additional "(" into if statement. after that i getting below mentioned error - unction] Script function failed on issue: SHD-11357, actionId: 1, file: <inline script> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script40.groovy: 6: unable to resolve class com.atlassian.jira.issue.UpdateIssueRequest @ line 6, column 1. import com.atlassian.jira.issue.UpdateIssueRequest ^ Script40.groovy: 14: unable to resolve class UpdateIssueRequest.UpdateIssueRequestBuilder @ line 14, column 46. est.UpdateIssueRequestBuilder issueReque ^ Script40.groovy: 14: unable to resolve class UpdateIssueRequest.UpdateIssueRequestBuilder @ line 14, column 68. Builder issueRequestBuilder = new Update ^ 3 errors also i followed the url u refer. on that url you provide below mentioned example - import com.atlassian.jira.ComponentManager; import com.atlassian.jira.issue.IssueManager; IssueManager issueManager = ComponentManager.getInstance().getIssueManager(); Issue issue = issueManager.getIssueObject("ABC-12345"); in that script i can not understand what ("ABC-12345") is. is this issue key ? if so then do i need to mention a particular issue id in it. i do not understand

Vasiliy Zverev
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 13, 2015

"ABC-12345" is: ABC - is an project key 12345 - is an issue number into the project. Could you provide version of your JIRA instance? UpdateIssueRequest.UpdateIssueRequestBuilder is compatible since JIRA 6.3.

Sys Admin December 13, 2015

hi zverov, we are using jira 6.2.7

Vasiliy Zverev
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 13, 2015

Since use issueManager.updateIssue(ComponentAccessor.getJiraAuthenticationContext().getUser(), issue, ventDispatchOption.ISSUE_UPDATED, false) Instead issueManager.updateIssue(ComponentAccessor.getJiraAuthenticationContext().getUser(), issue, updIssReq); And delete import of UpdateIssueRequest.UpdateIssueRequestBuilder into header.

Sys Admin December 14, 2015

hi zverev, 1. i have replaced the line you have mentioned. 2. but i have not understand which line i have to delete. i have used below mentioned script right now - import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.event.type.EventDispatchOption import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.IssueManager import com.atlassian.jira.issue.fields.CustomField /** * Script for copy value from one custom field to another */ //Prepare to update UpdateIssueRequest.UpdateIssueRequestBuilder issueRequestBuilder = new UpdateIssueRequest.UpdateIssueRequestBuilder(); issueRequestBuilder.eventDispatchOption(EventDispatchOption.ISSUE_UPDATED); issueRequestBuilder.sendMail(false); UpdateIssueRequest updIssReq = new UpdateIssueRequest(issueRequestBuilder); CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager(); CustomField cstFld = customFieldManager.getCustomFieldObjectByName("Jira Issue Key"); if (cstFld_From != null) { issue.setCustomFieldValue(cstFld, issue.getKey()) issueManager.updateIssue(ComponentAccessor.getJiraAuthenticationContext().getUser(), issue, ventDispatchOption.ISSUE_UPDATED, false); } but using this script below mentioned error occured - wFunction] Script function failed on issue: SHD-11367, actionId: 1, file: <inline script> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script44.groovy: 13: unable to resolve class UpdateIssueRequest.UpdateIssueRequestBuilder @ line 13, column 46. est.UpdateIssueRequestBuilder issueReque ^ Script44.groovy: 13: unable to resolve class UpdateIssueRequest.UpdateIssueRequestBuilder @ line 13, column 68. Builder issueRequestBuilder = new Update ^ Script44.groovy: 16: unable to resolve class UpdateIssueRequest @ line 16, column 20. UpdateIssueRequest updIssReq = new UpdateIssueRequest(issueRequestBuilder); ^ Script44.groovy: 16: unable to resolve class UpdateIssueRequest @ line 16, column 32. UpdateIssueRequest updIssReq = new UpdateIssueRequest(issueRequestBuilder); ^ 4 errors could you please look into this. sorry to bother you again

Vasiliy Zverev
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 14, 2015

Just delete this line: UpdateIssueRequest.UpdateIssueRequestBuilder issueRequestBuilder = new UpdateIssueRequest.UpdateIssueRequestBuilder();

Sys Admin December 14, 2015

hi zverov, i have deleted the line as per your suggestion. right now my script is like below - import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.event.type.EventDispatchOption import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.IssueManager import com.atlassian.jira.issue.fields.CustomField /** * Script for copy value from one custom field to another */ //Prepare to update issueRequestBuilder.eventDispatchOption(EventDispatchOption.ISSUE_UPDATED); issueRequestBuilder.sendMail(false); UpdateIssueRequest updIssReq = new UpdateIssueRequest(issueRequestBuilder); CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager(); CustomField cstFld = customFieldManager.getCustomFieldObjectByName("Jira Issue Key"); if (cstFld_From != null) { issue.setCustomFieldValue(cstFld, issue.getKey()) issueManager.updateIssue(ComponentAccessor.getJiraAuthenticationContext().getUser(), issue, ventDispatchOption.ISSUE_UPDATED, false); } but still i got below mentioned error - Function] Script function failed on issue: SHD-11371, actionId: 1, file: <inline script> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script47.groovy: 15: unable to resolve class UpdateIssueRequest @ line 15, column 20. UpdateIssueRequest updIssReq = new UpdateIssueRequest(issueRequestBuilder); ^ Script47.groovy: 15: unable to resolve class UpdateIssueRequest @ line 15, column 32. UpdateIssueRequest updIssReq = new UpdateIssueRequest(issueRequestBuilder); ^ 2 errors

Vasiliy Zverev
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 14, 2015

Ok, try this: import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.event.type.EventDispatchOption import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.IssueManager import com.atlassian.jira.issue.fields.CustomField /** * Script for copy value from one custom field to another */ //Prepare to update CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager(); CustomField cstFld = customFieldManager.getCustomFieldObjectByName("Jira Issue Key"); if (cstFld_From != null) { issue.setCustomFieldValue(cstFld, issue.getKey()) issueManager.updateIssue(ComponentAccessor.getJiraAuthenticationContext().getUser(), issue, ventDispatchOption.ISSUE_UPDATED, false); }

Sys Admin December 14, 2015

hi zverov, after trying this script i am getting below mentioned error - Script function failed on issue: SHD-11377, actionId: 1, file: <inline script> groovy.lang.MissingPropertyException: No such property: cstFld_From for class: Script53 at Script53.run(Script53.groovy:16)

Sys Admin December 14, 2015

hi zverov, after trying the script you have provided i got below mentioned error - Script function failed on issue: SHD-11377, actionId: 1, file: <inline script> groovy.lang.MissingPropertyException: No such property: cstFld_From for class: Script53 at Script53.run(Script53.groovy:16) also i like to mention about a line - CustomField cstFld = customFieldManager.getCustomFieldObjectByName("Jira Issue Key") the "Jira Issue Key" field is a name of a test field which i want see with jira issue key value. is it right ?

Vasiliy Zverev
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 14, 2015

import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.event.type.EventDispatchOption import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.IssueManager import com.atlassian.jira.issue.fields.CustomField /** * Script for copy value from one custom field to another */ //Prepare to update CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager(); CustomField cstFld = customFieldManager.getCustomFieldObjectByName("Jira Issue Key"); if (cstFld != null) { issue.setCustomFieldValue(cstFld, issue.getKey()) issueManager.updateIssue(ComponentAccessor.getJiraAuthenticationContext().getUser(), issue, ventDispatchOption.ISSUE_UPDATED, false); }

Sys Admin December 14, 2015

hi zverov, yes i have used this script which you have send me already. the script is as below - import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.event.type.EventDispatchOption import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.IssueManager import com.atlassian.jira.issue.fields.CustomField /** * Script for copy value from one custom field to another */ //Prepare to update CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager(); CustomField cstFld = customFieldManager.getCustomFieldObjectByName("Jira Issue Key"); if (cstFld_From != null) { issue.setCustomFieldValue(cstFld, issue.getKey()) issueManager.updateIssue(ComponentAccessor.getJiraAuthenticationContext().getUser(), issue, ventDispatchOption.ISSUE_UPDATED, false); } but after trying the script you have provided i got below mentioned error - Script function failed on issue: SHD-11377, actionId: 1, file: <inline script> groovy.lang.MissingPropertyException: No such property: cstFld_From for class: Script53 at Script53.run(Script53.groovy:16) also i like to mention about a line - CustomField cstFld = customFieldManager.getCustomFieldObjectByName("Jira Issue Key") the "Jira Issue Key" field is a name of a text field which i want see with jira issue key value. is it right ? or "Jira Issue Key" is a variable which you used for example. for my case it is a valid text field. this test field is not associate with any issue screen. when a issue will create (suppose - shd-11358) , "Jira Issue Key" will should be show in view screen with shd-11358 value. please suggest

Vasiliy Zverev
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 14, 2015

Now trouble is that we use variable cstFld to store an object to operate with custom field. Into if statement variable cstFld_From is used. But there is no defenition of this variable. A posted last comment from a smartphone since it is bad formated. import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.event.type.EventDispatchOption import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.IssueManager import com.atlassian.jira.issue.fields.CustomField /** * Script for copy value from one custom field to another */ //Prepare to update CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager(); CustomField cstFld = customFieldManager.getCustomFieldObjectByName("Jira Issue Key"); if (cstFld != null) { issue.setCustomFieldValue(cstFld, issue.getKey()) issueManager.updateIssue(ComponentAccessor.getJiraAuthenticationContext().getUser(), issue, ventDispatchOption.ISSUE_UPDATED, false); }

Sys Admin December 14, 2015

hi zverov, after using below mentioned script as per your suggestion - import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.event.type.EventDispatchOption import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.IssueManager import com.atlassian.jira.issue.fields.CustomField /** * Script for copy value from one custom field to another */ //Prepare to update CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager(); CustomField cstFld = customFieldManager.getCustomFieldObjectByName("Jira Issue Key"); if (cstFld != null) { issue.setCustomFieldValue(cstFld, issue.getKey()) issueManager.updateIssue(ComponentAccessor.getJiraAuthenticationContext().getUser(), issue, ventDispatchOption.ISSUE_UPDATED, false); } i am getting below mentioned error - Script function failed on issue: SHD-11378, actionId: 1, file: <inline script> groovy.lang.MissingPropertyException: No such property: issueManager for class: Script54 at Script54.run(Script54.groovy:19)

Vasiliy Zverev
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 14, 2015

import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.event.type.EventDispatchOption import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.IssueManager import com.atlassian.jira.issue.fields.CustomField /** * Script for copy value from one custom field to another */ //Prepare to update CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager(); CustomField cstFld = customFieldManager.getCustomFieldObjectByName("Jira Issue Key"); if (cstFld != null) { issue.setCustomFieldValue(cstFld, issue.getKey()) ComponentAccessor.getIssueManager().updateIssue(ComponentAccessor.getJiraAuthenticationContext().getUser(), issue, ventDispatchOption.ISSUE_UPDATED, false); }

Sys Admin December 14, 2015

hi zverov, after using latest script the error is bit different. please find the error below - Script function failed on issue: SHD-11381, actionId: 1, file: <inline script> groovy.lang.MissingPropertyException: No such property: ventDispatchOption for class: Script57 at Script57.run(Script57.groovy:19)

Vasiliy Zverev
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 14, 2015

Missed "e". Here is a corrected script import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.event.type.EventDispatchOption import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.IssueManager import com.atlassian.jira.issue.fields.CustomField /** * Script for copy value from one custom field to another */ //Prepare to update CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager(); CustomField cstFld = customFieldManager.getCustomFieldObjectByName("Jira Issue Key"); if (cstFld != null) { issue.setCustomFieldValue(cstFld, issue.getKey()) ComponentAccessor.getIssueManager().updateIssue(ComponentAccessor.getJiraAuthenticationContext().getUser(), issue, eventDispatchOption.ISSUE_UPDATED, false); }

Sys Admin December 14, 2015

hi zverov, after using very latest script now error is as below - Script function failed on issue: SHD-11384, actionId: 1, file: <inline script> groovy.lang.MissingPropertyException: No such property: eventDispatchOption for class: Script60 at Script60.run(Script60.groovy:19)

Vasiliy Zverev
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 14, 2015

I tested this code on my JIRA, good luck: import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.event.type.EventDispatchOption import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.IssueManager import com.atlassian.jira.issue.fields.CustomField /** * Script for copy value from one custom field to another */ //Prepare to update CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager(); CustomField cstFld = customFieldManager.getCustomFieldObjectByName("Jira Issue Key"); if (cstFld != null) { issue.setCustomFieldValue(cstFld, issue.getKey()) ComponentAccessor.getIssueManager().updateIssue(ComponentAccessor.getJiraAuthenticationContext().getUser().getDirectoryUser(), issue, EventDispatchOption.ISSUE_UPDATED, false); }

Vasiliy Zverev
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 14, 2015

On issue screen press button "Admin" and into dropdown list select "Where my field". There are two common reasons that field is not shown: value is empty or field is not present on a sceen. Try this.

Sys Admin December 14, 2015

Hi Zverov, Thanks a ton !!!! It is working after I associate this field with view issue screen. Thank you very much for your constant support. I highly appreciate your grat support on behalf of my team

Vasiliy Zverev
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 14, 2015

Great, could you mark this answer as solution for future users of Atlassian Answers to make them sure that this will help them?

Sys Admin December 14, 2015

Zverov, Ofcourse. I have marked as answer

Sys Admin December 14, 2015

Hi Zverov, You can also use "Copy Value from Othe Field" post function for this

JIRA_USER March 8, 2017

Sys Admin / Vasiliy,

Could you please advice me Where do I add your working code? IS that in Postfunction of create Transition or in other place. Could you please advice me step wise?

Thanks in advance.

 

Suggest an answer

Log in or Sign up to answer