how to log script post function changes in the history?

Paz Grimberg March 19, 2017

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

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Thanos Batagiannis [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 21, 2017

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

Paz Grimberg March 26, 2017

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

0 votes
Niclas Sandstroem
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 19, 2017

Hey Paz,

Have you tried the standard set value?

issue.setCustomFieldValue(cf, "my value")

Br, Niclas

Paz Grimberg March 19, 2017

yes, didnt work to update the multi-select checkbox field..

Niclas Sandstroem
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 20, 2017
Paz Grimberg March 20, 2017

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)
Niclas Sandstroem
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 20, 2017

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?

Paz Grimberg March 20, 2017

isnt it for behaviours only?

Niclas Sandstroem
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 20, 2017

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.

TAGS
AUG Leaders

Atlassian Community Events