Hi all,
I have a single select custom field that I am trying to set the value using a post function as below. But, the change does not reflect. I have tried doing multiple different things suggested on the blogs but nothing is working. Kindly, advice as to what I am missing.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.fields.config.FieldConfig
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
MutableIssue mutableIssue = (MutableIssue) issue
CustomField obj_releaseType = customFieldManager.getCustomFieldObjectByName('Release Type')
FieldConfig fieldConfigRT = obj_releaseType.getRelevantConfig(issue)
Option value = ComponentAccessor.getOptionsManager().getOptions(fieldConfigRT)?.find { it.toString() == 'Test - Internal'}
if(value)obj_releaseType.updateValue(null, mutableIssue,new ModifiedValue(mutableIssue.getCustomFieldValue(obj_releaseType), value),new DefaultIssueChangeHolder())
issueManager.updateIssue(issue.getReporter(), mutableIssue, EventDispatchOption.ISSUE_UPDATED, false)
Instead of using the updateValue function I have also tried using the below function.
mutableIssue.setCustomFieldValue(obj_releaseType, value)
Hi @Rakesh Katte
if(rtvalue)obj_releaseType.updateValue(null, mutableIssue,new
"rtvalue" doesn't exist on your code, I guess is "value".
I don't know if this is a typo only on this code or also on your original code.
Oops!! Just a typo while adding the question to the blog. Corrected it now. Thanks for pointing out.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think your code seems ok.
In what order is your post function ?
On the screen where you add the post function, there is:
1.-Creates the issue originally
2.- Re index an issue ....
3.- Fire event
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It's the first one in the below list of steps:
Scripted post function
Set issue status to the linked status of the destination workflow step.
Add a comment to an issue if one is entered during a transition.
Update change history for an issue and store the issue in the database.
Re-index an issue to keep indexes in sync with the database.
Fire a Generic Event event that can be processed by the listeners.
Edit
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you try on the 4th place?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Still nothing. I have changed the order to the below:
Set issue status to the linked status of the destination workflow step.
Add a comment to an issue if one is entered during a transition.
Update change history for an issue and store the issue in the database.
Scripted post function
Re-index an issue to keep indexes in sync with the database.
Fire a Generic Event event that can be processed by the listeners.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I dont have all those , Im not sure why .
The way I do it is "Add post function" then "Script Post-Function[Script Runner] "
Then, my order is :
Create the issue originally
Re index
Fire a Issue Created
And then I add my script.
So , you can try to add it on the last position just to discard that.
Another thing I would do is
log.warn ComponentAccessor.getOptionsManager().getOptions(fieldConfigRT)
to see the options that are available on your select, just to be sure it is reading it correctly.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It turned out to be a missing import :( in my actual code. Since I don't have access to the filesystem where Jira is deployed, i don't get to see the logs easily. Hence, the goof up.
@Gustavo Félix Apologize for wasting your time. But, thanks much for looking into this.
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.