can anyone help me I have a custom Field named Product where I need to capture the timestamp of this field changed and save this to different custom field which will be of Date type.
I am trying to achieve this by using a Script-runner Addon.
The new field where I will save this will be Hidden field.
Any guidance would be very appreciated :) Thank you!
Hi @Arjunsingh Hajari ,
if you want to change your field during edit/transition, you can setup a behaviour (https://scriptrunner.adaptavist.com/5.4.47/jira/behaviours-overview.html) based on Product field with the following code :
import java.util.Date;
FormField productFF = getFieldById(getFieldChanged());
Date product = (Date)productFF.getValue();
FormField yourNewFieldFF = getFieldById("customfield_12345");//YOUR CF ID HERE
yourNewFieldFF.setFormValue(product);
yourNewFieldFF.setHidden(true);
Please, make sure that your field is into edit/transition screen.
Hope this helps.
Fabio
Hello @Fabio Racobaldo _Herzum_ ,
Thanks for your reply actually I used the below code
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import java.sql.Timestamp
import com.atlassian.jira.issue.MutableIssue
//Issue issue = issue this will not work since we are making this change for a listener so Issue class may not work.
MutableIssue issue = event.issue as MutableIssue
def change = event?.getChangeLog()?.getRelated("ChildChangeItem").find {it.field == "mySourceField"}
if (change) {
def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("myTargetField")
def changeHolder = new DefaultIssueChangeHolder()
def now = new Timestamp(new Date().getTime())
cf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cf), now),changeHolder)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.