Forums

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

Can you help with behaviour on service desk to populate fields on form using existing issue

Nicole Downes
Contributor
February 16, 2020

We create an issue using a recruitment request on the Service desk. This issue contains data such as job title, start date, office, business unit, etc.

I would like to populate the same fields in our Onboarding request in the Service Desk using the information already entered on the recruitment request.

I have created an Issue Picker scripted field to allow the user to select the correct recruitment request. 

I have been advised I need to use the behaviours getValue() method with the issueManager.getIssueByCurrentKey("issuekey") method to get the issue object. But I just don't know how to structure up the script to achieve it.

Can someone provide a sample of how this would be achieved. Please include all imports and definitions as well.

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Darryl Lee
Community Champion
May 4, 2022

Hi - this can actually be done with Automation.

Turns out my answer had broken images, so I've just written a new one here:

If somebody wants to actually do this with Groovy and Scriptrunner, you should feel free to submit an answer.

Vimalraj Periyasamy
December 6, 2022

I would like to run this with Groovy and scriptrunner. Can you provide me the code snippet for the same?

Bastian Wedler
December 13, 2022

Hi @Vimalraj Periyasamy 

using groovy/scriptrunner is not that complicated. Maybe the following examples of writing users from a multi user field into a table, helps you:

{code:java}
package de.metamorphant.jira.scripts.Examples

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.security.JiraAuthenticationContext
import com.atlassian.jira.user.ApplicationUser

CustomFieldManager customFieldManager = ComponentAccessor.getComponent(CustomFieldManager)
IssueManager issueManager = ComponentAccessor.getComponent(IssueManager)
JiraAuthenticationContext jiraAuthenticationContext = ComponentAccessor.getComponent(JiraAuthenticationContext)

ApplicationUser currentUser = jiraAuthenticationContext.getLoggedInUser()

CustomField usersField = customFieldManager.getCustomFieldObject("customfield_12345")
List<ApplicationUser> userList = issue.getCustomFieldValue(usersField) as List<ApplicationUser>

StringBuilder stringBuilder = new StringBuilder()

//Adding the Header
stringBuilder.append("||Username||User displayname||Email||Active||")

//iterating through the user list and adding the rows to the table
userList.each {
stringBuilder.append("\n|${it.username}|${it.displayName}|${it.emailAddress}|${it.isActive().toString()}")
}

//set table in multiline textField of mutable issue
CustomField textField = customFieldManager.getCustomFieldObject("customfield_23456")
MutableIssue mutableIssue = issue as MutableIssue
mutableIssue.setCustomFieldValue(textField, stringBuilder.toString())

//Write to database
issueManager.updateIssue(currentUser, mutableIssue, EventDispatchOption.DO_NOT_DISPATCH, false)

{code}

Kim Tso
December 28, 2022

@Bastian Wedler  Could I know whether any interface that help to convert renderedBody content into customfield value?

 

There are so many kinds of wiki style editor provided.

TAGS
AUG Leaders

Atlassian Community Events