Hello Everyone
I'm using Jira DC v 8.22.2 and Im trying to achieve some requirements using script runner.
The script will update the Progress% of the "Demand" issue type based on the "Weight" and "Progress%" of the "milestone" sub tasks. However, I'm facing error (unable to resolve class) in import com.atlassian.jira.issue.fields.CustomFieldManager
any idea about this error ?
sure, HYG
Awesome, thank you!
So, to answer your initial question, the reason this was failing is because the import line is:
import com.atlassian.jira.issue.CustomFieldManager
Rather than
import com.atlassian.jira.issue.fields.CustomFieldManager
But once I fixed that there were other issues with the script, and we can solve all of those and make it easier to write and read using HAPI. So, if I rewrite this script in HAPI:
def issue = Issues.getByKey('WEB-8') // Replace with the actual issue key
// Get sub-tasks
def issueSubtasks = issue.getSubTaskObjects()
def totalWeight = 0
def weightedProgress = 0
issueSubtasks.each { subtask ->
def progress = subtask.getCustomFieldValue('progress%') ?: 0
def weight = subtask.getCustomFieldValue('weight') ?: 0
if(weight > 0){
weightedProgress += (progress * weight)
totalWeight += weight
}
}
// Calculate the final progress%
def finalProgress = totalWeight > 0 ? (weightedProgress / totalWeight) : 0
// Update the demand issue's progress%
issue.update {
setCustomFieldValue('progress%', finalProgress)
}
Could you give this a try and let me know how you get on please?
Kind regards,
Bobby
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for your support Bobby, i got one error related to the field name "Progress %"
Could you check and advice
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Apologies, it looks like to update a number field you need to pass a string! (No idea why)
So this:
setCustomFieldValue('Custom Number Field', finalProgress)
becomes this:
setCustomFieldValue('Custom Number Field', finalProgress.toString())
Could you try this and let me know? And in the meantime I will try to find out why that is the case.
Kind regards,
Bobby
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Fadi Shahwan ,
Are you able to share your script? It would make it much easier to see what the problem might be :-)
Kind regards,
Bobby
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Spend the day sharpening your skills in Atlassian Cloud Organization Admin or Jira Administration, then take the exam onsite. Already ready? Take one - or more - of 12 different certification exams while you’re in Anaheim at Team' 25.
Learn more
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.