Set field value by postfunction

Issue #43 resolved
Former user created an issue

Hello! Are there any ways to set tree-customfield field value (silgle choise) by postfunction? (Have sil, scriptrunner, jsu,jmwe)

Comments (5)

  1. Yury Oboz repo owner

    import com.onresolve.scriptrunner.runner.customisers.WithPlugin
    import com.onresolve.scriptrunner.runner.customisers.PluginModule
    import ru.slie.jira.tree.manager.TreeSchemaManager
    import com.atlassian.jira.component.ComponentAccessor
    import com.atlassian.jira.issue.CustomFieldManager
    import com.atlassian.jira.issue.fields.CustomField
    import com.atlassian.jira.issue.MutableIssue
    import com.atlassian.jira.event.type.EventDispatchOption
    
    @WithPlugin("ru.slie.jira.tree-customfield")
    
    @PluginModule
    TreeSchemaManager tsm
    
    CustomFieldManager cfm = ComponentAccessor.getCustomFieldManager()
    
    //def MutableIssue issue = ComponentAccessor.getIssueManager().getIssueObject("TR-1")
    
    CustomField treeSingleField = cfm.getCustomFieldObject(10100L) // customfield ID
    CustomField treeMultiField = cfm.getCustomFieldObject(10000L) // customfield ID
    
    
    /** get value by id **/
    //def value = tsm.getOptionById(49)
    
    
    /** get value by name **/
    /** Customfield, Node name, search limit; If customfield have only one connected schema - it good choice **/
    def options = tsm.findOptionByName(treeSingleField, "NMX/Q3-20/Requested", 1) 
    if (!options) {
        return "no options found";
    }
    def value = options.first()
    
    /** get schema **/
    /** this method do not search by path; will be fixed in next release **/
    //def schema = tsm.getSchema(treeSingleField.getRelevantConfig(issue))
    //if (!schema) {
    //    return "no assign schema for field"
    //}
    
    //def value = tsm.getOptionByName(schema, "NMX/Q3-20/Requested") // not working in current version, will be fixed in next release
    //def value = tsm.getOptionByName(schema, "Requested") // work
    
    issue.setCustomFieldValue(treeSingleField, value)
    issue.setCustomFieldValue(treeMultiField, [value])
    //ComponentAccessor.getIssueManager().updateIssue(ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(), issue, EventDispatchOption.DO_NOT_DISPATCH, false)
    

  2. Log in to comment