Hello!
I am trying to set a custom field of URL-type during the creation of a ticket, but it doesn't set the value at all. If I run the same code during another transition it works, so the code seems to be ok.
I have tried to change the order of the post function steps after reading a couple of other questions and answers, but with no luck.
I had the same problem before when setting the Resolution during creation (I know, it's a bit weird, but neeeded in this scenario). That worked after adding the post function "Stores updates to an issue (no change history is created)." before re-indexing.
So, here is my setup.
Post-functions:
And my code:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
def issueId = issue.getKey()
log.info(issueId)
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
def customField = customFieldManager.getCustomFieldObjectByName("<My field name>")
def link = "https://myurl.com/" + issueId
log.info(link)
issue.setCustomFieldValue(customField, link)
Try this.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
def issueId = issue.getKey()
def changeHolder = new DefaultIssueChangeHolder();
log.info(issueId)
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField customField = customFieldManager.getCustomFieldObjectByName("<My field name>")
def link = "https://myurl.com/" + issueId
log.info(link)
field.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customField), link),changeHolder);
Keep this function at no 4 (after re-indexing).
Thank you for the answer. Seems like there is an error on line 11.
"unable to resolve class CustomField @line 11, column 13"
The text "customField" is marked as errornous.
Maybe I have a different (older) version of Script Runner?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh we missed to import this!
import com.atlassian.jira.issue.fields.CustomField
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you so much, worked perfectly. Can you explain why my initial solution didn't work, ie what did I miss to consider?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It works perfectly if you use set method followed by store method.
// apply changes to Jira -----------------------
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)Refer this. https://community.atlassian.com/t5/Agile-articles/Three-ways-to-update-an-issue-in-Jira-Java-Api/ba-p/736585
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.