Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×Hi
i have a transition with a customfield ( type : Hideable Free Text Field )
and the system field "Comment", set by default on my transition screen.
what i want to do is to copy the value of the comment into the customfield ( it will be hiden) on a postfonction custom script with script runner.
the customfield is also configured on the edit screen of the issue type i'm working on.
after searching, i came up with this code :
import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.ModifiedValue import com.atlassian.jira.issue.util.DefaultIssueChangeHolder import com.atlassian.jira.component.ComponentAccessor MutableIssue issue = (MutableIssue) issue; def customFieldManager = ComponentAccessor.getCustomFieldManager() def tgtField = customFieldManager.getCustomFieldObjects(issue).find {it.name == "test_Commentaire_client"} def changeHolder = new DefaultIssueChangeHolder() tgtField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(tgtField),transientVars.comment as string),changeHolder)
I do not have any errors on my logs , but the customfield is never updated after calling my transition.
Can you help me ?
You need to use issue.setCustomFieldValue to set the field's value in a postFunction. Also, use String, not 'string', which isn't a keyword in Java.
import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.ModifiedValue import com.atlassian.jira.issue.util.DefaultIssueChangeHolder import com.atlassian.jira.component.ComponentAccessor log.debug("Running script") MutableIssue issue = (MutableIssue) issue; def customFieldManager = ComponentAccessor.getCustomFieldManager() def tgtField = customFieldManager.getCustomFieldObjects(issue).find {it.name == "test_Commentaire_client"} def changeHolder = new DefaultIssueChangeHolder() def comment = transientVars.comment as String log.debug("$comment") issue.setCustomFieldValue(tgtField, comment) log.debug("Done")
As a side tip, you can put logging statements in your script to help you find its execution details in the logs. I have my logger set to show the debug statements shown above, but you'll probably have a higher setting by default (like log.warn).
thx for your answer Jonny,
but it works only if i set my Hideable Free Text Field customfield to "visible".
If I hide it, there is no update and the field
I'll try to search why, but if you have any idea ...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
setCustomField should work, even on hidden fields. How are you checking the value of the field? That is, how do you read the value of the field once it's hidden to confirm its value isn't getting set. Maybe this is a new question in its own right?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am checking the value in the database , table "customfieldvalue" .
When the field is visible , the value is updated, but when i hide it with the behavior plugin,
the value isn't getting updated.
So do you want me to create a new ticket for this ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Those hideable field types are a semi-experimental feature of ScriptRunner, and it occurs to me that what you're experiencing may be normal behaviour. Hideable fields marked as hidden by a behaviour can't even be read via the REST API. It would make sense to me that you wouldn't be able to set their value via the UI, as its existence ought to basically be hidden.
If you think that's not how it should work, feel free to raise an issue with us.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Last line might need to be changed to
tgtField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(tgtField),transientVars.comment as String),changeHolder)
as 'string' isn't a valid keyword in java/groovy.
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.