We are building a script listener that reads a custom field (Product(s) Multi Select) and will create issues in other projects based on these values.
The issue we are having is that we have a few members in our org that have changed their user names in the AD and we get an error status the user does not exist. This error only happens on the handful of users that have changed their AD Information. All other users work as expected.
This is the Log with the error we are getting:
Time (on server): Mon Jul 22 2019 13:17:42 GMT-0700 (Pacific Daylight Time)
The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.
2019-07-22 20:17:42,275 DEBUG [create request]: user nparmeter(nparmeter)
2019-07-22 20:17:42,277 DEBUG [create request]: newIssueType = IssueConstantImpl[[GenericEntity:IssueType][sequence,null][name,Enhancement Request][iconurl,/secure/viewavatar?size=xsmall&avatarId=10311&avatarType=issuetype][description,Enhancement Request][style,null][id,10500][avatar,10311]]
2019-07-22 20:17:42,277 DEBUG [create request]: status = Approved
2019-07-22 20:17:42,283 DEBUG [create request]: change = [newvalue:[11701, 11235], field:Product(s) Multi Select, oldstring:POS Engineering, newstring:Clinical Apps,POS Engineering, id:780114, fieldtype:custom, oldvalue:[11235], group:576697]
2019-07-22 20:17:42,283 DEBUG [create request]: Old value : POS Engineering
2019-07-22 20:17:42,283 DEBUG [create request]: New value : Clinical Apps,POS Engineering
2019-07-22 20:17:42,283 DEBUG [create request]: Value changed by nparmeter(nparmeter) at 2019-07-22 20:17:41.509
2019-07-22 20:17:42,290 DEBUG [create request]: in create issue
2019-07-22 20:17:42,290 DEBUG [create request]: reporterId : obadilla
2019-07-22 20:17:42,307 WARN [create request]: Errors:
{reporter=The reporter specified is not a user.}
Error Messages: []
2019-07-22 20:17:42,307 DEBUG [create request]: in create issue
2019-07-22 20:17:42,307 DEBUG [create request]: reporterId : obadilla
2019-07-22 20:17:42,319 WARN [create request]: Errors: {reporter=The reporter specified is not a user.}
Any assistance would be appreciated. Again, this works without flaw for 99% of our users. Its only the users that have changed their AD information (username) does this cause an error.
Here is the script we are using:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.fields.CustomField
import org.apache.log4j.Logger
import org.apache.log4j.Level
def log = Logger.getLogger("create request")
log.setLevel(Level.DEBUG)
def issue = event.issue
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
log.debug("user ${user}")
def issueService = ComponentAccessor.issueService
def issueInputParameters = issueService.newIssueInputParameters()
def projectMgr = ComponentAccessor.getProjectManager()
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def linkMgr = ComponentAccessor.getIssueLinkManager()
def newIssueType = ComponentAccessor.getConstantsManager().getAllIssueTypeObjects().find{it.name=="Enhancement Request"}
log.debug("newIssueType = ${newIssueType}")
def duedateValue = issue.getDueDate()
log.debug("status = ${issue.status.name}")
if (issue.status.name == 'In Progress' || issue.status.name == 'Approved'){
def change = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "Product(s) Multi Select"}
log.debug("change = ${change}")
if (change) {
log.debug "Old value : ${change.oldstring}"
log.debug "New value : ${change.newstring}"
log.debug "Value changed by ${event.user} at ${event?.getChangeLog()?.created}"
//get project list
CustomField customField = customFieldManager.getCustomFieldObjectByName("Product(s) Multi Select");
List<Option> projects = (List<Option>) customField.getValue(issue);
def projectField = customFieldManager.getCustomFieldObjectByName("Jira Project")
// get custom fields
def bsiProject = projectMgr.getProjectObjByKey("IPV")
def hloeField = customFieldManager.getCustomFieldObjectByName("HLOE")
def bsaField = customFieldManager.getCustomFieldObjectByName("BSA")
def hqcodeField = customFieldManager.getCustomFieldObjectByName("HQ Code")
def participantField = customFieldManager.getCustomFieldObjectByName("Participants")
def reasonField = customFieldManager.getCustomFieldObjectByName("Request Reason")
def billableField = customFieldManager.getCustomFieldObjectByName("Billable")
def servicetaskField = customFieldManager.getCustomFieldObjectByName("ITPPM Service Task")
if (projects) {
projects.each { project ->
// create requests in each project:
// create request
def projectObj = projectMgr.getProjectObjByName(project.toString())
// if there is already a link for this project then don't create another one
def createIssue = true
linkMgr.getOutwardLinks(issue.id).each { link ->
// get jira project from linked issue to see if it matches this project
def destProject = link.getDestinationObject().getCustomFieldValue(projectField)
log.debug("projectObj = ${projectObj.name}")
log.debug("destProject = ${destProject}")
if (destProject.toString() == projectObj.name.toString()) {
log.debug("createIssue false")
createIssue = false
}
if (!createIssue) { return true }
}
if (createIssue) {
log.debug("in create issue")
issueInputParameters.setSummary("${projectObj.name.toString()} - ${issue.summary}")
issueInputParameters.setDescription(issue.description)
issueInputParameters.setProjectId(bsiProject.getId())
issueInputParameters.setIssueTypeId(newIssueType.id.toString())
if (issue.getReporterId()) {
issueInputParameters.setReporterId(issue.getReporterId())
}
issueInputParameters.setReporterId(issue.getReporterId())
issueInputParameters.setIssueTypeId(newIssueType.id.toString())
try {
if (duedateValue) {
def formattedDueDate = duedateValue.format('d/MMM/yy')
issueInputParameters.setDueDate(formattedDueDate)
}
def hloeValue = issue.getCustomFieldValue(hloeField)
if (hloeValue) {
issueInputParameters.addCustomFieldValue(hloeField.getId(), hloeValue.toString())
}
def hqcodeValue = issue.getCustomFieldValue(hqcodeField)
if (hqcodeValue) {
issueInputParameters.addCustomFieldValue(hqcodeField.getId(), hqcodeValue.toString())
}
// Container Link
def cfContainerLink = customFieldManager.getCustomFieldObjectByName('Container Link')
def issueId = issue.getId()
issueInputParameters.addCustomFieldValue(cfContainerLink.getId(), issue.getId().toString())
issueInputParameters.setPriorityId(issue.priority.getId())
def validationResult = issueService.validateCreate(user, issueInputParameters)
//log.debug("validationResult = ${validationResult.getIssue().key}")
if (validationResult.valid) {
log.debug("is valid")
def result = issueService.create(user, validationResult)
def newIssue = result.getIssue()
// add link to intake request
linkMgr.createIssueLink(issue.getId() as Long, newIssue.getId() as Long, newIssueType.id as Long, null, user);
List<IssueLink> allInIssueLinks = ComponentAccessor.getIssueLinkManager().getInwardLinks(issue.id)
log.debug(allInIssueLinks.size().toString())
for (Iterator<IssueLink> inIterator = allInIssueLinks.iterator(); inIterator.hasNext();) {
IssueLink issueLink = (IssueLink) inIterator.next()
linkMgr.createIssueLink(issueLink.getSourceId() as Long, newIssue.getId() as Long, newIssueType.id as Long, null, user)
issueManager.updateIssue(user, newIssue, EventDispatchOption.DO_NOT_DISPATCH, false)
}
//Setup List fields
//JAMA Integration field
def fieldConfig = projectField.getRelevantConfig(newIssue)
def projectValue = ComponentAccessor.optionsManager.getOptions(fieldConfig)?.find {
it.toString() == project.toString()
}
log.debug "project value = ${projectValue}"
newIssue.setCustomFieldValue(projectField, projectValue)
def servicetaskPPMValue = issue.getCustomFieldValue(servicetaskField)
if (servicetaskPPMValue)
{
// set ITPPM field in issue
//Object parentcfITTPMField = parentITPPMValue
newIssue.setCustomFieldValue(servicetaskField, (Object) servicetaskPPMValue)
}
//reason field
Option reasonFieldVal = (Option) issue.getCustomFieldValue(reasonField)
newIssue.setCustomFieldValue(reasonField, reasonFieldVal)
log.debug "reasonFieldVal = ${reasonFieldVal}"
// checkboxes
Option billableValue = (Option) issue.getCustomFieldValue(billableField)
newIssue.setCustomFieldValue(billableField, billableValue)
log.debug "billableValue = ${billableValue}"
issueManager.updateIssue(user, newIssue, EventDispatchOption.DO_NOT_DISPATCH, false)
} else {
log.warn(validationResult.errorCollection)
}
} catch (e1) {
log.warn("error = ${e1}")
}
}
}
}
} else {log.debug("changed field not project")}
}