Hi,
I have a post function script that updates checkbox custom field value on linked issue with the following method:
def changeHolder = new DefaultIssueChangeHolder(); involvedField.updateValue(null, ActivityIssue, new ModifiedValue(ActivityIssue.getCustomFieldValue(involvedField), values),changeHolder); ActivityIssue.store() // update in DB (same as reindex)
How can i make this change to be shown under target issue (ActivityIssue) history?
I tried to use ServiceIssue and also issueManager.updateIssue(currentUser, ActivityIssue, EventDispatchOption.ISSUE_UPDATED, false) but it didnt work for me ...
Thakns!
Paz
Community moderators have prevented the ability to post new answers.
Hi Paz,
Try the following custom script post function
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.context.IssueContextImpl import com.atlassian.jira.issue.fields.config.FieldConfig def issue = issue as MutableIssue def issueContext = new IssueContextImpl(issue.projectId, issue.issueTypeId) def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Checkboxes") def fieldConfig = cf.getRelevantConfig(issueContext) as FieldConfig def optionsToSet = ComponentAccessor.getOptionsManager().getOptions(fieldConfig)?.findAll { it.value in ["Yes", "Maybe"] } issue.setCustomFieldValue(cf, optionsToSet)
Make sure that this post function will be the first one.
Please let me know if this does the trick.
regards, Thanos
Hi Thanos,
Thanks for your reply.
I figured this issue with the following lines:
ActivityIssue.setCustomFieldValue(involvedField, values) ComponentAccessor.getIssueManager().updateIssue(user, (MutableIssue)ActivityIssue, EventDispatchOption.DO_NOT_DISPATCH, false) ActivityIssue.store()
this works and also write to history but i still have an error red line under the first row you recommanded. can you advise?
Thanks!
Paz
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Paz,
Have you tried the standard set value?
issue.setCustomFieldValue(cf, "my value")
Br, Niclas
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.
What kind of fault do you run into? Seeing multiple people being able to update check-box fields on this forum.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I created a list of options to update the field with, issue.setCustomFieldValue(cf,
"my value"
) didnt work for it..
def involvedField = customFieldManager.getCustomFieldObjectByName('Involved Teams') def involvedValue = ActivityIssue.getCustomFieldValue(involvedField) ArrayList<Option> myList =(ArrayList<Option>) involvedValue ArrayList<Option> values = new ArrayList<Option>(); for(Option option : myList){ if(option.getValue().toString() != team.toString()){ values.add(option) } } def changeHolder = new DefaultIssueChangeHolder(); involvedField.updateValue(null, ActivityIssue, new ModifiedValue(ActivityIssue.getCustomFieldValue(involvedField), values),changeHolder); ActivityIssue.store()// update in DB (same as reindex)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
From Script runner site:
// same example but setting a multiselect - also same for checkboxes fields def subComponentFld = getFieldByName("Subcomponent") customField = customFieldManager.getCustomFieldObject(subComponentFld.getFieldId()) config = customField.getRelevantConfig(getIssueContext()) options = optionsManager.getOptions(config) def optionsToSelect = options.findAll { it.value in ["Oranges", "Lemons"] }
If you try to play around with your field like this instead?
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.
The example is from behaviours but you should be able to use the optionsManager and the same method to find the values to set that you want.
Then all that remain is feeding that into:
issue.setCustomFieldValue(cf, value)
https://answers.atlassian.com/questions/24642640
You might not need to worry about context since you already have the issue etc.
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.