I am not able to create a ticket

Venkata Sagar July 19, 2022

Hi Team,

I have an Script, I have kept it in Post function. The Scenario is when we select the Label "PDE_Support " the Due date should be auto populate based on the Priority.

The Script is working fine , checked it on the Previous Tickets. The Problem here is like when i select the PDE_Support Label. the Issues are not creating getting error like 

We can't create this issue for you right now, it could be due to unsupported content you've entered into one or more of the issue fields. If this situation persists, contact your administrator as they'll be able to access more specific information in the log file.

Script:

/*import com.atlassian.jira.issue.label.Label;
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue
import java.sql.Timestamp;
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.customfields.option.Option
import groovy.time.*
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.config.PriorityManager
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import com.atlassian.sal.api.user.UserManager
import static com.atlassian.jira.issue.IssueFieldConstants.PRIORITY


def constantsManager = ComponentAccessor.getConstantsManager()

def userUtil = ComponentAccessor.getUserUtil()
log.debug ComponentAccessor.getComponent(UserManager)

def priority = issue.getPriority()
def pname=priority.name.toString()

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()

Issue issue = issue

def duedate = customFieldManager.getCustomFieldObject("customfield_47440")


Calendar cal = Calendar.getInstance();
def temp = cal.getTimeInMillis();
def add = 0;
def x = 1000*24*60*60L
def mydueDate = new Timestamp(cal.getTimeInMillis());

Set<Label> labels = issue.getLabels()

if (labels.find { it.getLabel() == "PDE_Support"}) {

if (pname == "0")
{
add = 1*x
temp = temp+add
mydueDate.setTime(temp)

issue.setCustomFieldValue(duedate, mydueDate)

def currentUserObj = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
issueManager.updateIssue(currentUserObj, issue, EventDispatchOption.DO_NOT_DISPATCH, false)

}
else if (pname == "1")
{
add = 14*x
temp = temp+add
mydueDate.setTime(temp)

issue.setCustomFieldValue(duedate, mydueDate)

def currentUserObj = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
issueManager.updateIssue(currentUserObj, issue, EventDispatchOption.DO_NOT_DISPATCH, false)

}
else if (pname == "2")
{
add = 28*x
temp = temp+add
mydueDate.setTime(temp)

issue.setCustomFieldValue(TargetCompletionDate, mydueDate)

def currentUserObj = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
issueManager.updateIssue(currentUserObj, issue, EventDispatchOption.DO_NOT_DISPATCH, false)

}else if(pname == "3")
{
add = 90*x
temp = temp+add
mydueDate.setTime(temp)

issue.setCustomFieldValue(duedate, mydueDate)

def currentUserObj = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
issueManager.updateIssue(currentUserObj, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
}
else if(pname == "4")
{
add = 180*x
temp = temp+add
mydueDate.setTime(temp)

issue.setCustomFieldValue(duedate, mydueDate)

def currentUserObj = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
issueManager.updateIssue(currentUserObj, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
}

}

*/

1 answer

0 votes
Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 16, 2023

Hi @Venkata Sagar ,

that error should be related to object type that is not consistent with the custom field type.

DateTime custom field supports Timestamp object type. Try to define mydueDate as Timestamp and not as def.

Timestamp mydueDate = new Timestamp(cal.getTimeInMillis());

Fabio

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events