Hello,
I am using a scripted post function to setup the due date but I keep getting else value being set even if the value is Four Months
Script:-
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import java.text.SimpleDateFormat
import com.atlassian.jira.issue.comments.CommentManager
import java.sql.Timestamp
import com.atlassian.core.util.DateUtils
import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def userUtil = ComponentAccessor.getUserUtil()
//def log = Logger.getLogger("com.onresolve.scriptrunner.runner.ScriptRunnerImpl")
//log.setLevel(Level.INFO)
MutableIssue mutableIssue = issue
def RiskValidity = customFieldManager.getCustomFieldObject("customfield_19703")
def RiskValidityV = issue.getCustomFieldValue(RiskValidity)
log.info("The value is " + RiskValidityV)
if(RiskValidityV == "Two Months"){
issue.setDueDate(new Timestamp((new Date() + 60).time))
}
else if (RiskValidityV == "Four Months"){
issue.setDueDate(new Timestamp((new Date() + 120).time))
}
else if (RiskValidityV == "Six Months"){
issue.setDueDate(new Timestamp((new Date() + 180).time))
}
else {
issue.setDueDate(new Timestamp((new Date() + 180).time))
}
Hi Sunil,
From your code, it appears that you are adding just the number of days to the current date. Instead, it would help if you tried to convert it to milliseconds first.
You could try out this working code:-
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
import java.sql.Timestamp
def mutableIssue = issue as MutableIssue
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def customFieldManager = ComponentAccessor.customFieldManager
def issueManager = ComponentAccessor.issueManager
def validity = customFieldManager.getCustomFieldObjectsByName("Validity")[0]
def validityValue = validity.getValue(mutableIssue).toString()
def timeInMillis = (24 * 60 * 60 * 1000) as Long
if(validityValue == "Two Months") {
mutableIssue.setDueDate(new Timestamp( System.currentTimeMillis() + (timeInMillis * 60) as Long ))
} else if(validityValue == "Four Months") {
mutableIssue.setDueDate(new Timestamp( System.currentTimeMillis() + (timeInMillis * 120) as Long ))
} else if(validityValue == "Six Months") {
mutableIssue.setDueDate(new Timestamp( System.currentTimeMillis() + (timeInMillis * 180) as Long ))
} else {
mutableIssue.setDueDate(new Timestamp( System.currentTimeMillis() + (timeInMillis * 180) as Long ))
}
issueManager.updateIssue(loggedInUser, mutableIssue, EventDispatchOption.ISSUE_UPDATED, false)
Please note, this sample code is not 100% exact to your environment. Hence, you will need to make the required modifications.
Also, please try using the Issue Manager to update the Issue, i.e.:-
issueManager.updateIssue(loggedInUser, mutableIssue, EventDispatchOption.ISSUE_UPDATED, false)
to save your changes.
Below are some print screens of the test results for your reference:-
I hope this helps to solve your question :)
Thank you and Kind regards,
Ram
Hi there, on my phone so don't have access to a code editor but I believe this is because you are comparing RiskValidityV which is a different class to the string. Try RiskValidityV.toString() == "Two Months" and let us know if that works? If it doesn't can you run RiskValidityV.class and let us know what class it is?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Everyone,
Thank you for your inputs.
I was able to achieve it.
Regards,
Sunil
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.