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

Getting an error while placing a Jira Group in a Group Picker (Single Group) using ScriptRunner

Sriharsha August 29, 2024

Hi,

I wanted to place an assets attribute values present as an attribute called Groups (used Jira Groups) in a Group Picker field called Assignment Group using a ScriptRunner Post-function based on a value of Asset Object field selected while creating the ticket. I'm using the below script - 

 

 

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.groups.GroupManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
// Assuming this script is used in a post-function or listener where 'issue' is already available
def issueKey = "ITSC-53" // 'issue' is provided in the context
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def groupManager = ComponentAccessor.getGroupManager()
def issueManager = ComponentAccessor.getIssueManager()

def issue = issueManager.getIssueObject(issueKey)

//  actual custom field IDs
def assetFieldId = "customfield_31604" // ID of the asset field
def assignmentGroupFieldId = "customfield_31400" // ID of the Assignment Group field
// Retrieve custom fields by ID
def assetField = customFieldManager.getCustomFieldObject(assetFieldId)
def assignmentGroupField = customFieldManager.getCustomFieldObject(assignmentGroupFieldId)
// Get custom field value from the issue
def assetFieldValue = issue.getCustomFieldValue(assetField)?.toString()

def assetFieldValueString = assetFieldValue.toString()
// Retrieve the list of groups associated with the asset field value
def groupName
switch (assetFieldValueString) {
    case "Finance":
        groupName = "ITSC: Finance" 
        break
    case "HR":
        groupName = "ITSC: HR/HCM" 
        break
    default:
        groupName = null
        break
}
if (groupName) {
    def group = groupManager.getGroup(groupName)
    if (group) {
        // Set the value in the "Assignment Group" field
        issue.setCustomFieldValue(assignmentGroupField, group)
        issueManager.updateIssue(ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(), issue, EventDispatchOption.DO_NOT_DISPATCH, false)
        log.debug("Group ${groupName} found for asset value ${assetFieldValue} and set in Assignment Group field.")
    } else {
        log.warn("Group ${groupName} not found.")
    }
} else {
    log.warn("No group mapped for the selected asset value.")
}
////////////////////////////////////////////////////////////////////////////////////////////////
I'm getting the WARN - No group mapped for the selected asset value.
I have correct mapping in Assets.
Can anyone help me ASAP? Thanks, in advance!

1 answer

Suggest an answer

Log in or Sign up to answer
1 vote
Tomasz Kowalczyk
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 30, 2024

hi @Sriharsha 
try to log value from assetFieldValueString i think you're getting there an objectKey not a name of a group. 

 

Sriharsha August 30, 2024

Sure, I will check and update you. Thank you for your response, @Tomasz Kowalczyk !

TAGS
AUG Leaders

Atlassian Community Events