Hi,
Can someone provide some code snippet for Jira Behaviors plugin that shows how to retrieve the original value of a custom field?
I need to compare against the original value to see if the field has been changed and take some action if necessary.
Thanks
--Andrew
Hi.
This is the way I used to change the DueDate.
import java.text.SimpleDateFormat
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
Date oldDueDate = underlyingIssue.getDueDate()
Date newDueDate = new SimpleDateFormat("dd/MM/yy").parse(getFieldById("duedate").getFormValue().toString())
if (oldDueDate != newDueDate) {
getFieldById("comment").setRequired(true)
} else {
getFieldById("comment").setRequired(false)
}
Hi Joshua Yamdogo @ Adaptavist, how can I revert back the original value if the custom field has set to blank/null in a group picker field?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If I may be so bold,
Why don't you simply create a transition for this?
If this field is required at creation, then put it on the Create and View screens only, and leave it off the Edit screen.
The tranisition could be from all to all, called something like "Update MyField," and you can put this field and the comment field on the screen for this transtion.
Then simply require Comment on the transition using a validator.
Would this cover your requirement?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for the suggestion, April.
I think this is a bit much for my requirements.
The field is required during Create as well as Edit.
Thanks
--Andrew
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Does this need to be accomplished with behaviours? It sounds like this would be more suited to be done in a listener. For example, you can make a listener that fires on an Issue Created or Issue Updated Event (or all Issue Events). If someone updated the Priority field, check to see what the original value was and what it was changed to. Then, you can perform additional actions based off that information.
def change = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find{ it.field=='priority' }
if (change) {
def oldValue = change.oldstring
def newValue = change.newstring
log.debug ("Value changed from ${oldValue} to ${newValue}")
// your actions if the field has changed
}
Log statement:
DEBUG admin [onresolve.scriptrunner.runner.ScriptRunnerImpl] Value changed from Low to High
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
The requirement is to make the Comment field mandatory if the user changes the custom field.
Aren't Listeners a bit too after-the-fact for my requirements?
Thanks
--Andrew
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, you're correct that listeners wouldn't be very useful in that case. However, your question seemed focus on getting the specific value before and after the field was changed. I don't see why that would be needed if all you want to do is make the comment field mandatory based on a custom field value.
You'd just need a behaviour that would continually check the value of the custom field. It would run on the Create Issue, Update/Edit Issue, Assign Issue, and Workflow Transition screens. If it sees that the custom field has the wrong value, make the comment field mandatory.
def customField = getFieldByName('YourCustomFieldName')
def commentField = getFieldById("comment")
if (customField.getValue() != "Some value") {
commentField.setRequired(true)
}
else {
commentField.setRequired(false)
}
If the user changes the custom field to something it's not supposed to be, make the comment field required. Else, don't make the comment field required.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
We have a custom field that is a pull-down, so the user can only choose from one of the provided choices.
I need to know if the user selected a different choice of this custom field. If so, make the Comment field mandatory when the user clicks on "Edit" and changes that custom field. The Comment field would then be required before the user can click on "Update" to save.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Andrew,
For example:
def customField = getFieldByName('YourCustomFieldName')
def commentField = getFieldById("comment")
if (customField.getValue() != "A") {
commentField.setRequired(true) //if the user selects B or C as a choice, make the comment field required
}
else {
commentField.setRequired(false) //if the user does not select B or C, the comment field will not be required
}
Does the logic here match what you're trying to accomplish?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Joshua
My requirement is i don't care what choice is selected. Every value is correct.
The Comment field is mandatory for the user to explain why the custom field value was changed.
Thanks
--Andrew
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.