You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
Hi,
I am trying to do two things here. Firstly, I want to turn a string from an array into an numeric and then save that into a numeric custom field (Story Points).
The script works perfectly other than the part above.
This is an example of the array,
def storyTypeTasks =
["Summary": "Config - Verify Circuit", "Description": "Config - Verify Circuit", "Task Type": "Technical task", "Component":"Configuration Team", "Story Points": "15"],
import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
def log = Logger.getLogger("com.bttv.MDTStoryPostFunction")
log.setLevel(Level.DEBUG)
def constantManager = ComponentAccessor.getConstantsManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueFactory = ComponentAccessor.getIssueFactory()
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def subTaskManager = ComponentAccessor.getSubTaskManager()
// Get project Type field details
def storyTypeField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Story type")
log.debug "storyTypeField = " + storyTypeField
// Get story type for current story
Issue story = issue
def storyType = story.getCustomFieldValue(storyTypeField)
log.debug "storyType = '" + storyType + "'"
//get story points
def Storypointsfield = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Story Points")
// Find matching story type and tasks to create
def storyTypeTaskTemplate = storyTypeTasks.find{ it.key == storyType.getValue() }
log.debug "storyTypeTaskTemplate = '" + storyTypeTaskTemplate + "'"
// This story project type is templated
if(storyTypeTaskTemplate) {
log.debug "Processing template..."
log.debug "Story '" + story.summary + "' with type '" + storyType + "' has task template"
log.debug "storyTypeTaskTemplate: '" + storyTypeTaskTemplate + "'"
// Iterate thru list of tasks to create
storyTypeTaskTemplate.getValue().each {
log.debug "storyTypeTaskTemplate.each: '" + it + "'"
// Build issue
MutableIssue newTask = issueFactory.getIssue()
newTask.setSummary(it["Summary"])
newTask.setDescription(it["Description"])
newTask.setParentObject(story)
newTask.setProjectObject(story.getProjectObject())
newTask.setIssueTypeId(constantManager.getAllIssueTypeObjects().find{
it.getName() == "Sub-task"
}.id)
//////////////////////////////////////////////////////////
// THIS IS THE LINE THAT FAILS
//Set Temp story Points
newTask.setCustomFieldValue("Story Points",it["Story Points"])
//////////////////////////////////////////////////////////
// Set component
def theComponent = ComponentAccessor.getProjectComponentManager().findByComponentName(story.getProjectObject().getId(),it["Component"])
newTask.setComponent([theComponent])
// Create task
def newTaskParams = ["issue" : newTask] as Map<String,Object>
Issue task = issueManager.createIssueObject(user, newTaskParams)
// Create subtask linkage
subTaskManager.createSubTaskIssueLink(story, task, user)
log.debug "Issue with summary ${task.summary} created"
}
// Not template for this type of epic
} else {
log.debug "Story '" + story.summary + "' with type '" + storyType + "' has NO task template"
}
Hello @Peter Ellis
Did you ever solve this issue?
Are you getting an error message? If so, please share that.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.