I have a request form with some insight fields on it. I am trying to set the value of the insight fields on the form (this is BEFORE the issue is created). The script looks like:
def countryField = getFieldById("customfield_16805")
def storedObjectBean = objectFacade.loadObjectBean(theCountryId)
countryField.setError(storedObjectBean.toString()) // this works -> Canada (TVM-256028)
//none of these work
//countryField.setFormValue(storedObjectBean)
//countryField.setFormValue([storedObjectBean])
//countryField.setFormValue(theCountryId)
//countryField.setFormValue([theCountryId])Since the issue is not yet created, there is no issue variable and I cannot use the mutableIssue.setCustomFieldValue() which usually works.
Any ideas?
The issue is solved and I guess it is related to the following fact. The trigger is executed prior to the actual update. The changes I am doing in the code above is on the issue and not on the updateIssue. Therefore it get's overridden. Following code does the trick:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.priority.Priority
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.event.type.EventDispatchOption;
//set default values
String impactDefault = "Medium"
String UrgencyDefault = "Medium"
//create variables
def issue = event.issue as Issue
def impact = impactDefault
def urgency = UrgencyDefault
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
//get helpers
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def constantsManager = ComponentAccessor.getConstantsManager()
def issueService = ComponentAccessor.getIssueService()
//get the custom fields for the priority check
try{
def urgencyField = customFieldManager.getCustomFieldObjectByName("Urgency")
urgency = issue.getCustomFieldValue(urgencyField) as String
if(urgency==null){urgency=UrgencyDefault}
}catch(Exception ex){}
try{
def impactField = customFieldManager.getCustomFieldObjectByName("Impact")
impact = issue.getCustomFieldValue(impactField) as String
if(impact==null){impact = impactDefault}
}catch(Exception ex){}
//define the priority
String priority ="";
log.error("U:" + urgency + " I:" + impact)
switch(urgency.trim()){
case "High":
log.error("Switch: " + urgency)
switch(impact.trim()){
case "High":
log.error("Switch: " + impact)
priority = "Highest"
break;
case "Medium":
log.error("Switch: " + impact)
priority = "High"
break;
case "Low":
log.error("Switch: " + impact)
priority = "Medium"
break;
}
break;
case "Medium":
switch(impact.trim()){
case "High":
priority = "High"
break;
case "Medium":
priority = "Medium"
break;
case "Low":
priority = "Low"
break;
}
break;
case "Low":
switch(impact.trim()){
case "High":
priority = "Medium"
break;
case "Medium":
priority = "Low"
break;
case "Low":
priority = "Lowest"
break;
}
break;
}
log.debug(priority)
//create an object for the input parameters
def issueInputParameters = new IssueInputParametersImpl()
//get the priorities
for(Priority priority1: ComponentAccessor.getConstantsManager().getPriorities()){
log.error(priority1.getName() + " " +priority )
if(priority1.getName().equals(priority)){
issueInputParameters.setPriorityId(priority1?.id)
}
}
issueInputParameters.setSkipScreenCheck(true)
//validate the update
def validationResult = issueService.validateUpdate(user, issue.id, issueInputParameters)
//execute the updat
if (validationResult.isValid()) {
issueService.update(user, validationResult)
} else {
log.error validationResult.errorCollection.errors
}
Kind regards,
Matt
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.