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

insert Value "alexan38" in multi user picker custom field

MGH
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 7, 2023

Hi,

I would like to use the "Postfunction" when creating a ticket, with precondition. i.e.
If:
1) in the CustomField "Berechtigungskategorie" of type "Select List (cascading)" the child value is equal to "Verzeichnisberechtigungen".
2) in the CustomField "Antragsteller..." of the type "User selection (single user)" value is not in the AD group "SG-Dep-FMP".
then in the CustomField-Value "Genehmigende" of Type "User Picker (multiple users)" enter Value/Username "alexan38" and update ticket.

I can run my code in the "Script Console" without error, but the value in the CustomField "Genehmigende" is missing when I open the ticket.
I would be very grateful for any help.
my whole code is here:

-----------------------------

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.*
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.customfields.impl.CascadingSelectCFType

def issueManager = ComponentAccessor.getIssueManager()
def optionsManager = ComponentAccessor.optionsManager

//predefined content
def jirakey =issueManager.getIssueCount().toString()
//def jirakey = getUnderlyingIssue().getKey().toString()
//def issue = issueManager.getIssueObject(jirakey)
Issue issue = issueManager.getIssueObject("TIFOSD-500")

def customFieldManager = ComponentAccessor.getCustomFieldManager()
// Get CustomFieldsvalue
def cFGenehmigende = customFieldManager.getCustomFieldObject("customfield_13522") // Genehmigende
def cFGenehmigendeValue = cFGenehmigende.getValue(issue)

def cfAntragsteller = customFieldManager.getCustomFieldObject("customfield_15320") // AntragsstellerIn/ Fachverantwortliche(r)
def cfAntragstellerValue = cfAntragsteller.getValue(issue)

// Liste User in AD-Gruppe 'SG-Dep-FMP'
def groupManager = ComponentAccessor.groupManager
def FAMGroupUsers = groupManager.getUsersInGroup("SG-Dep-FMP")

//get saved CustomField: Berechtigungskategorie[0]
def cfBerechtigungskategorie = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(15345)
if (cfBerechtigungskategorie != null) {
    Map mapValue = issue.getCustomFieldValue(cfBerechtigungskategorie) as Map
    def cfcfBerechtigungskategorieFieldValue = mapValue.get(null).toString()

    // def for Berechtigungskategorie-Optionen
    def customField = customFieldManager.getCustomFieldObjectsByName("Berechtigungskategorie")[0]
    def fieldConfig = customField.getRelevantConfig(issue)

    // Define the Option variable as a List Type
    List options = optionsManager.getOptions(fieldConfig)

    def cfBerechtigungskategorieValue = issue.getCustomFieldValue(15345)
    HashMap<String, Option> hashMapEntries = (HashMap<String, Option>) cfBerechtigungskategorieValue
    if ((cfBerechtigungskategorieValue != null) && (cfAntragstellerValue != null) && (groupManager.getUsersInGroup("SG-Dep-FMP").contains(cfAntragstellerValue) == false)) {
        Option parent = hashMapEntries.get(CascadingSelectCFType.PARENT_KEY)
        Option child = hashMapEntries.get(CascadingSelectCFType.CHILD_KEY)
        // Gehen Sie alle Optionen durch
        child.each {
            log.info("it.toString: " + it.toString())
            if (it.toString() == "Verzeichnisrechte") {
                //cFGenehmigende.setFormValue("alexan38")
                issue.setCustomFieldValue(cFGenehmigende, "alexan38")
                log.info("CFGenehmValue: " + issue.getCustomFieldValue(13522))  
            }
        }
    }
}

-----------------------------.

Best regards.
Masoud

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events