Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Want to Set priority based on the questionnaire.

SysAdmin May 18, 2025

Hi,

We have below questionnaire as single select list custom field in Jira Datacenter v9.4.1.

We want to sum the answers and then divide the sum by the number of questions.

Then map the average with priority of the Jira issue.

 

Below are the question with their options:

"Will this demand directly contribute to increased revenue or decreased cost for ARC?"

No = 1

Partially = 2

Yes = 3

"Does this address a known vulnerability or security gap (data, API, app, infra)?"

No = 1

Partially = 2

Yes = 3 

"Will delaying this demand expose the business to operational risk or financial loss?"

No = 1

Partially = 2

Yes = 3

 

These questions are on a transition screen. I have created a script listener just to sum the score and print the sum in an another number field. But even that is not working. There are no error when the listener gets executed but the Score field still remains unset. The event for the listener is selected as Issue Created, Issue Updated and Generic Event

Below is the listener script:

 

import com.atlassian.jira.component.ComponentAccessor

def issue = event.issue
def customFieldManager = ComponentAccessor.customFieldManager
def issueService = ComponentAccessor.issueService
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser

// Get the custom fields
def revenueField = customFieldManager.getCustomFieldObjectByName("Revenue Impact")
def securityField = customFieldManager.getCustomFieldObjectByName("Security Gap")
def riskField = customFieldManager.getCustomFieldObjectByName("Operational Risk")
def totalScoreField = customFieldManager.getCustomFieldObjectByName("Total Score")

// Mapping function from option to score
def mapValue = { def option ->
switch (option?.toString()) {
case "No":
return 1
case "Partially":
return 2
case "Yes":
return 3
default:
return 0
}
}

// Get selected option values and map to scores
def score1 = mapValue(issue.getCustomFieldValue(revenueField))
def score2 = mapValue(issue.getCustomFieldValue(securityField))
def score3 = mapValue(issue.getCustomFieldValue(riskField))

def totalScore = score1 + score2 + score3

// Set the Total Score field
def issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.addCustomFieldValue(totalScoreField.id, totalScore.toString())

def validationResult = issueService.validateUpdate(user, issue.id, issueInputParameters)
if (validationResult.isValid()) {
issueService.update(user, validationResult)
}

 

How to get this working, Any thoughts?

 

Regards,

0 answers

Suggest an answer

Log in or Sign up to answer