Hello, I want to fire an event in case a custom field "employee type" changed value. When I look at the examples for the condition at the Script Listener "Fires an event when a condition is true", I see 2 examples which I need to combine but I don't know how:
Example 1 gives me the check for the change of value of the field. Example 2 gives me the check a specific value of a 2-word custom field. And now: how do I combine these 2 to get my check on changed value of my custom field "Employee type"? Thanks.
Hello,
I guess it would be like this:
import com.atlassian.jira.component.ComponentAccessor
def customFieldName = "your custom field name"
def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName(customFieldName)
if (issue.getCustomFieldValue(cf).toString().equals(originalIssue.getCustomFieldValue(cf).toString)) {
return false;
} else {
return true
}
Hello Alexy, thanks for the help. Unfortunately I get an errormessage (see screenprint attached). "tostring" seems to be the problem. How to correct?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import com.atlassian.jira.component.ComponentAccessor
def customFieldName = "your custom field name"
def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName(customFieldName)
if (issue.getCustomFieldValue(cf).toString().equals(originalIssue.getCustomFieldValue(cf).toString())) {
return false;
} else {
return true
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Alexey, that seems to work fine! Thank you. The only thing that doesn't work now is the notification I setup in the Notification Scheme based on the new event.
Thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Alexey, the code is syntax correct, but it doesn't send a notification to my email address. What I did:
As I can't preview this based on an issue, I put the same coding as above in an other new listener who sends a custom email. In that option I can preview what happens based on a real issue. If I do that review, I get the message "the condition evaluated to false". So, the coding above says my custom field "employee type" didn't change? And I know for sure it did! My custom field "employee type" is a select list single choice. Can that be the problem? Does this type of custom field need other coding?
Thank you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Could you add logging to your script and have a look in the logs, what the values are:
def customFieldName = "your custom field name"
def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName(customFieldName)
log.error("issue.getCustomFieldValue(cf).toString(): ${issue.getCustomFieldValue(cf).toString()}")
log.error("originalIssue.getCustomFieldValue(cf).toString(): ${originalIssue.getCustomFieldValue(cf).toString()}")
if (issue.getCustomFieldValue(cf).toString().equals(originalIssue.getCustomFieldValue(cf).toString())) {
return false;
} else {
return true
}
You can find logs in the atlassian-jira.log file.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Alexey, Thanks for thinking with me. I added the log coding and when I execute now I get following information:
The 2 log lines tell me that new and original value of my custom field "employee type" are both value "other" and that's not true. I changed value "Internal" to value "Other". So my original value is not correct. What's of in my coding making Jira think that both new and original are the same as they are not? Thank you for your help again.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
As far as I understand originalIssue does not take the current data of the issue. Let s try to do it antoher way:
import com.atlassian.jira.component.ComponentAccessor
def originalIssue = ComponentAccessor.getIssueManager().getIssueByCurrentKey(issue.getKey())
def customFieldName = "your custom field name"
def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName(customFieldName)
if (issue.getCustomFieldValue(cf).toString().equals(originalIssue.getCustomFieldValue(cf).toString())) {
return false;
} else {
return true
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry Alexey, doesn't make a difference. Is it a problem that my custom field is of type "select list (single choice)" and not a text field?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It should not make a difference. Do you put this script to a validator?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What do you mean by "do you put this script to a validator"? No, at the moment it is not part of my workflow, I created it as a listener in case my custom field "employee type" changes, independent from which workflow part the issue is in. Should it be connected to a validator?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ah, I see. that is why it does not work
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
To validate if a field was change in a listener, you should do like this:
def customFieldName = "your custom field name"
log.debug("changeItems: " + changeItems.toString())
while (i < changeItems?.size()) {
log.debug(changeItems.getAt(i).get("field"))
if (customFieldName.equals(changeItems.getAt(i).get("field"))) {
return true;
}
i++;
}
return false
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Alexey, sorry for my late response, busy with a lot of other Jira stuff. I'm sorry, but I don't understand your peace of code. I get to this point:
but why the red "x"? What in the syntax is wrong? I'm sorry, I'm not trained in this coding, all learning by myself, thanks for your help
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It could be static errors. You can execute this script
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Did you get this working? Im trying the very same thing with a custom field (Type - User picker multi) but i can seem to get the condition working?
My goal is when a user add's an assessor (user) on the edit screen the listener will run and create a sub-task for that assessor
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.