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?
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?
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); }
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
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?
"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)
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.
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.
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!
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.
Hi Zverov, After using this script no error occurred. But "Jira Issue Key" field also not showing in the view issue screen
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.
It looks like you're new here. Sign in or register to get started.