Hi,
I want to set date on a custom field using script runner. I am using the script below but it is giving me the date 1 month later not the current date. I have added the code in a Post Function.
code:
def csDate2 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Approved On")
Timestamp csDate1Value = (Timestamp) issue.getCreated()
Date csNewDateValue = new Date(csDate1Value.getTime() + 30*24*60*60*1000);
csDate2.updateValue(null, issue, new ModifiedValue("", (Object) csNewDateValue), new DefaultIssueChangeHolder())
Kindly advice
Thanks
Swarna
It gives you one month later, because you add 30*24*60*60*1000, which is 30 days after the current date. You should do it like this:
def csDate2 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Approved On")
Timestamp csDate1Value = (Timestamp) issue.getCreated()
Date csNewDateValue = new Date(csDate1Value.getTime());
csDate2.updateValue(null, issue, new ModifiedValue("", (Object) csNewDateValue), new DefaultIssueChangeHolder())
Hi Alexey,
Thanks for your help :)
The code is now working
Thanks
Swarna
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If my answer helped you, kindly accept it. In this case other users will be able to find this answer, if they have similair question.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Alexey Matveev, I'm trying to use this script, and am seeing the following errors. The second error says unable to resolve class ModifiedValue @ line 5, column 34 and unable to resolve class DefaultIssueChangeHolder @ line 5, column 82.
Any advice?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You need to add as the first line this line:
import java.sql.Timestamp
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.
When I type in the import code, I'm getting errors that the system is unable to resolve class
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.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
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.