Responsive image

JIRA ScriptRunner listener. Field saves the date of change another field.

Hello!


I would like show You how with scriptrunner listener You can save in the specific field the date of change of another field.
When I change field "Baseline Due Date", the date in another field "Epic Baseline Edited Date" saves the current date.
If I clear field "Baseline Due Date", another field "Epic Baseline Edited Date" is also cleared.

Both fields are date picker type, of course you can use the type you need.

But I set field "Epic Baseline Edited Date" only on the view screen, which prevents editing access to this field. There we save the date when another field changes.
The second field "Baseline Due Date" is added on all screens.

Now we need to create a new script listener.
Set a project. Set an event. And put the script.
Безымянный.png

In your case you need to change the field name. This also works for system fields, but the name of the system field may be different. I recommend using "log.error(event.getChangeLog().getRelated('ChildChangeItem')) " in order to catch the name of the system field.

Video:



I hope it was helpful.

Source
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

def cfm = ComponentAccessor.getCustomFieldManager()
def watch = cfm.getCustomFieldObjectByName("Baseline Due Date")
def watchValue = event.issue.getCustomFieldValue(watch)
def updatedWatch = cfm.getCustomFieldObjectByName("Epic Baseline Edited Date")
def today = new java.sql.Timestamp(new Date().getTime())

if (event.getChangeLog().getRelated('ChildChangeItem').find{ it.field == 'Baseline Due Date'}){

def changeHolder = new DefaultIssueChangeHolder()

if( event.issue.getCustomFieldValue(watch) == null ){
updatedWatch.updateValue(null, event.issue, new ModifiedValue(null, null), changeHolder)
}else{
updatedWatch.updateValue(null, event.issue, new ModifiedValue(null, today), changeHolder)
}

}

//log.error(event.getChangeLog().getRelated('ChildChangeItem'))



Thanks!
Link Name Created
3KCH.png Безымянный.png 2019-11-03 17:36:38
Files
0 0 0 0 0

Created:2019-11-03 17:21:31
Viewed:83

User
Time

Comment body

code Guest comment will be added after moderating
Send