With the behaviour plugin having an issue detecting a change for a field

Sorry still new to behaviours so please forgive this ignorance which hopefully might be an easy question.

We are currently on JIRA 6.3.1 using ScriptRunner 4.1.3.9.

Specifically the issue is I have a behaviour created upon a custom field.

For that specific field I am trying to detect when there is a change.for this field and the "Fix Version/s" is not set throw an error that prevents the user from updating.

Currently I have the below where the specific field is customfield_10038.

Is there something obvious that I am doing wrong or misunderstanding?

def field = getFieldById(getFieldChanged())

if (field == "customfield_10038" && fixVersion.getValue() == "") {

    field.setError("You aren't allowed to checkin.")

}

else {

    field.clearError()

}

 

 

Thanks in advance.

1 answer

2 votes
Mahesh S Community Champion Nov 29, 2016

Though hadn't tried hands-on, I believe this could help you. smile

def cusField = getFieldById(getFieldChanged())
def fix = getFieldByName("Fix Version/s") 
if ((fix.getValue() == null) || (fix.getValue() == "")) 
{
    cusField.setError("You aren't allowed to checkin.")
}
else {
    cusField.clearError()
}

Check the minor mistakes keenly. 

Hi Mahesh,

Thanks for that response. I had initially tried this but had an issue where even though this custom field didn't change when I go to hit the edit button for the bug, it perceives that this field has changed and as such runs this check. This is problematic in that you may want to edit another field in that bug but cannot now. Any ideas for this?

 

Thanks,

Randy 

So, you could do a check to see whether the custom field has actually changed, as well as checking whether Fix Version is empty.

def cusField = getFieldById(getFieldChanged())
def fix = getFieldByName("Fix Version/s")
def fixVersionEmpty = (fix.getValue() == null) || (fix.getValue() == "")
def customFieldChanged = cusField.getValue() != underlyingIssue.getCustomFieldValue(cusField)
if (fixVersionEmpty && !customFieldChanged)
{
    cusField.setError("You aren't allowed to checkin.")
}
else {
    cusField.clearError()
}

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Fadoua M. Boualem
Published yesterday in Trello

Using Trello to manage events

As a Jira power user, I was at first doubtful that Trello could benefit my workflow. Jira already uses boards (ones you can customize!), so why would I even need to use Trello?! In this post you will...

431 views 5 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you