Newbie to Scriptrunner and Scripting and Java. Working on video tutorial that calculates new date and time based on custom field:
it starts out and term of contract is date and time and adds 30 or 60 or 90 days to due date and assigns it to due date.
I was typing this into ScriptRunner console and then TimeinMillis() was depreciated-- I need help to use new method.
// this script takes final payment date and calculates expiration date 364 days in future
//adaptation of youtube video
//GET value of Valid Period custom field (30, 60, 90 days)
//GET Build logic around what data is due date
//CALCULATION of due date
//INPUT of the due date
//issue type contract--workflow post function
// uses custom fields: Contract Warranty Expiration=10400, a date field,
// custom field valid period-- date field =10402
// and Invoice Final Payment Date=10401
//Get Managers
import com.atlassian.jira.component.ComponentAccessor //library call
import com.atlassian.jira.issue.MutableIssue
import java.util.*
def VALIDPERIOD = 10402 as Long //define custom field static field id in my instance
def datetoset
def customFieldManager=ComponentAccessor.getCustomFieldManager()
//get current issue in my instance
def issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("SP-24")
// GET custom field
def validPeriodCustomField = customFieldManager.getCustomFieldObject(VALIDPERIOD)
// get value
def validPeriodValue = issue.getCustomFieldValue(validPeriodCustomField)
// log.warn tells me what value it is pulling
log.warn("This is check getting valid period from issue:" + validPeriodValue)
// LOGIC around new contract due date --date to set
if (validPeriodValue=='30') {
datetoset = 30
}
else if (validPeriodValue == '60'){
datetoset = 60
}
else {
datetoset = 90
}
log.warn('date to set:'+ datetoset + ' line 41')
//set the value on issue using JAVA API
Calendar myDueDate = Calendar.getInstance()
myDueDate.add(Calendar.DATE, datetoset) //set new value
//get timestamp in java so JIRA can read it
//Timestamp dueDateTimestamp = new Timestamp(myDueDate.getTimeinMillis())
//from this point is where I get lost.
calendar.getTimeinMills()
issue.setDueDate(dueDateTimestamp)
log.warn('new due date is: ' + dueDateTimestamp)
log.warn ('issue due date is ' )
Please try the code below.
Calendar myDueDate = Calendar.getInstance();
myDueDate.add(Calendar.DATE, datetoset);
Timestamp dueDateTimestamp = new Timestamp(myDueDate.getTime().getTime())
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.