Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Why is Behaviours script not triggered after inline edit?

NeilW February 9, 2016

I have written a Behaviours script that triggers and functions correctly when I use the Edit form and change the Due Date field.  However, when I do an inline edit of the Due Date field, the script does not seem to be triggered.  Any help would be appreciated.

import java.util.Date
import java.sql.Timestamp
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.fields.config.FieldConfig
import com.atlassian.jira.issue.customfields.option.Options
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import org.apache.log4j.Logger
import org.apache.log4j.Level
Logger log = Logger.getLogger("com.tripadvisor.groovy")
log.setLevel(Level.DEBUG)
log.debug "BEHAVIOURS DUE DATE SCRIPT IS STARTING"
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
OptionsManager optionsManager = ComponentAccessor.getOptionsManager()
if (underlyingIssue != null)
{
    FormField dueDateFormField = getFieldById(fieldChanged)
    FormField isLateFormField = getFieldByName("Is Late")
    
    Timestamp originalDueDate = underlyingIssue.getDueDate()
    if (originalDueDate == (Object) null)
    {
        // log.debug "originalDueDate is null"        
    }
    else
    {
        log.debug "originalDueDate: " + originalDueDate
        Date now = new Date()
        log.debug "now: " + now
        int daysUntilDue = originalDueDate - now
        log.debug "daysUntilDue: " + daysUntilDue
        if (daysUntilDue < 1)
        {
            // Set Is Late custom field value to "Yes"
            CustomField isLateCustomField = customFieldManager.getCustomFieldObject(isLateFormField.getFieldId())
            FieldConfig isLateConfig = isLateCustomField.getRelevantConfig(getIssueContext())
            Options allIsLateOptions = optionsManager.getOptions(isLateConfig)
            Collection relevantIsLateOptions = allIsLateOptions.findAll { it.value == "Yes" }
            // log.debug "relevantIsLateOptions: " + relevantIsLateOptions
            Collection<String> isLateKeys = relevantIsLateOptions.collect { it.optionId.toString() } 
            isLateFormField.setFormValue(isLateKeys)
        }
    }
}
log.debug "BEHAVIOURS DUE DATE SCRIPT IS COMPLETE"

2 answers

1 vote
Kristian Walker _Adaptavist_
Community Champion
February 29, 2016

Hi Neil,

Behaviours only works on the Create and Edit screens for an issue. Inside Newer versions of Script Runner then Inline editing is automatically disabled when a behaviour is added to a field.

For older versions as a workaround you can look to use JavaScript to disable in-line editing as described in the question here.

I hope this helps.

Thanks

Kristian

0 votes
NeilW February 9, 2016

It seems (based on an old answer) that inline editing should be disabled for this field, but it is not.  I am using OS X 10.10.5 and Chrome Version 47.0.2526.106 (64-bit).  The same applies to Mac Firefox 42.0.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events