Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,554,348
Community Members
 
Community Events
184
Community Groups

Update numerical custom field from string array

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"
}

1 answer

0 votes
Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Dec 22, 2022

Hello @Peter Ellis 

Did you ever solve this issue?

Are you getting an error message? If so, please share that.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events