Hi,
I have written a script to extract claim numbers and then if there is a single unique claim number, update the status on the issue. But when I try to execute the script, I get the below error.
The claim number updates in the field when I remove the logic to update the status and the code for updating the status runs perfectly fine when I run it on the console. But the problem arises when I run this as part of an automation rule triggered when issue is created. Can you please help with what I am doing wrong?
"Script function failed on Automation for Jira rule: Read and set Claim Number, Issue Type, file: <inline script>, No signature of method: com.atlassian.jira.issue.managers.RequestCachingIssueManager.call() is applicable for argument types: () values: [] Possible solutions: wait(), any(), wait(long), each(groovy.lang.Closure), any(groovy.lang.Closure), tap(groovy.lang.Closure)"
Script -
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.comments.CommentManager
import java.util.regex.Pattern
import java.util.regex.Matcher
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.issue.MutableIssue;
def summary=issue.getSummary()
def description=issue.getDescription()
def claimNumbers =[]
def issueManager = ComponentAccessor.issueManager()
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
MutableIssue issueToUpdate = (MutableIssue) issue;
//The transition ID is now hardcoded for To Be Processed. Change this to accomodate all statuses
def tobeProcessedTransitionId = 21
def workflowManager = ComponentAccessor.getWorkflowManager()
def workFlow = workflowManager.getWorkflow(issue)
def issueService = ComponentAccessor.issueService()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def claimNumberField = customFieldManager.getCustomFieldObjects(issueToUpdate).find {it.name == "Claim Number"}
//Match claim number pattern WCQ****** and return a list of claim numbers from Summary
def claimNumbersInSummary = summary.findAll(Pattern.compile(/\bWCQ[0-9]*/,Pattern.CASE_INSENSITIVE))
//Match claim number pattern WCQ****** and return a list of claim numbers from Description
def claimNumbersInDescription
def claimNumbersInDescriptionUpperCase
def claimNumbersSummaryUpperCase = claimNumbersInSummary.collect{it.toUpperCase()}
claimNumbers.addAll(claimNumbersSummaryUpperCase)
if(description!=null)
{
claimNumbersInDescription =description.findAll(Pattern.compile(/\bWCQ[0-9]*/,Pattern.CASE_INSENSITIVE))
claimNumbersInDescriptionUpperCase = claimNumbersInDescription.collect{it.toUpperCase()}
claimNumbers.addAll(claimNumbersInDescriptionUpperCase)
}
//This is to remove duplicate claim numbers regardless of case
claimNumbers.unique()
// Convert claim numbers list to comma separated string
String claimNumbersCommaSeparated=claimNumbers.asList().join(",").toString()
//Update Claim Number field in the issue
if (claimNumberField) {
def changeHolder = new DefaultIssueChangeHolder()
claimNumberField.updateValue(null, issueToUpdate, new ModifiedValue(issueToUpdate.getCustomFieldValue(claimNumberField), claimNumbersCommaSeparated),changeHolder)
}
log.warn(" Cliam Numbers Size: " + claimNumbers.size())
log.warn("Workflow transitions:"+workFlow.getLinkedStep(issue.getStatus()).getActions().name)
if(claimNumbers.size()==1)
{
def transitionValidationResult = issueService.validateTransition(currentUser,issueToUpdate.id,tobeProcessedTransitionId, new IssueInputParametersImpl())
def issueObjectID = issueToUpdate.getId()
log.warn("Transition Valid? :" +transitionValidationResult.isValid())
if (transitionValidationResult.isValid()) {
def transitionResult = issueService.transition(currentUser, transitionValidationResult)
}
}