validation
select jiraaccount,displayname from mcigeneralname where jiraaccount = ?
search sql
select jiraaccount,displayname from mcigeneralname
where lower(jiraaccount) like lower(?) || '%'
configuration script :
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.customfields.option.Option
import com.onresolve.scriptrunner.canned.jira.fields.editable.database.SqlWithParameters
import com.atlassian.jira.component.ComponentAccessor;
def userinfousername = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser().getUsername()
String userinfo = userinfousername
getSearchSql = { String inputValue, Issue issue, String originalValue ->
new SqlWithParameters(
"select jiraaccount,displayname from mcigeneralname where jiraaccount like ? || '%' and jiraaccount = ?",
[inputValue,userinfo]
)
}
getValidationSql = { String id, Issue issue,String originalValue ->
new SqlWithParameters("""
select jiraaccount,displayname from mcigeneralname
where displayname = ? and jiraaccount = ?
"""
, [id, userinfo])
}
when userinfo variable set to a string it works but when the current user is passed to the script it's not working
for example userinfo = 'm.moeini'
After going through the code you shared above, I have a question: i.e. can you confirm that the displayname column matches the Username instead of the User's Display Name?
If not, instead of using:-
def userinfousername = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser().getUsername()
it would be better if you used:-
def userinfousername = ComponentAccessor.jiraAuthenticationContext.loggedInUser.displayName
Also, I suggest upgrading your ScriptRunner plugin to the latest release so you can use the HAPI feature to simplify your code.
For the sample above, when using HAPI, all you need to do is:-
import com.adaptavist.hapi.jira.users.Users
....
....
....
Users.loggedInUser.displayName
I am looking forward to your feedback and clarification.
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.