The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

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

Scripted field for multi user picker field

Ambica Seshasayee
June 6, 2019

Hi,

I have a Scripted field whose template is "User Picker (multiple users".

I have the following script written, but the script is still not loading the field. Can you help?

----

import com.atlassian.jira.component.ComponentAccessor
import groovy.sql.Sql
import org.ofbiz.core.entity.ConnectionFactory
import org.ofbiz.core.entity.DelegatorInterface
import com.atlassian.jira.user.ApplicationUser

import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.MutableIssue;
import java.util.*

import com.atlassian.jira.user.util.UserUtil;
import com.atlassian.jira.user.util.UserManager;

import java.sql.Connection

def delegator = (DelegatorInterface) ComponentAccessor.getComponent(DelegatorInterface)
String helperName = delegator.getGroupHelperName("default");

log.error "Good so far 0";

def sqlStmt = """
SELECT bizuser
FROM <myschema>.jbizusers
where <myschema>.jbizusers.jissue=\'""" + issue.getKey() + "\'";

log.error "Good so far 1"
Connection conn = ConnectionFactory.getConnection(helperName);
Sql sql = new Sql(conn);
String user = null;

log.error "Good so far 2";

UserUtil userUtil = ComponentAccessor.getUserUtil();
UserManager userManager = ComponentAccessor.getUserManager();
ApplicationUser jiraUser = null;
List<ApplicationUser> jiraUsers = [];

try {

StringBuffer sb = new StringBuffer();
log.error "Good so far 3";
sql.eachRow(sqlStmt) { row ->
user = "$row.bizuser";
log.error "USER: " + user;
jiraUser = userManager.getUserByName(user);
jiraUsers.add(jiraUser);
//users.add(jiraUser)
}
}
finally {
sql.close()
}

log.error "Good so far 4"
log.error "JiraUsers size: " + jiraUsers.size()
return jiraUsers

 

The Preview for any issue shows the output correctly, with the Application Users identified.

However, the corresponding scripted field is not getting loaded for the same issue.

Any inputs, thanks!

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Josh_Kochelek
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 Champions.
August 27, 2019

@Ambica Seshasayee - Did you happen to find a solution for this? I am having the same issue. The preview works fine, but nothing is visible on the issue screen.

TAGS
AUG Leaders

Atlassian Community Events