MohammadReza moeini
MohammadReza moeini

Reputation: 190

Get current user for database lookup in scriptrunner not working

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'

How can i pass currentuser t configuration script?

Upvotes: 1

Views: 177

Answers (1)

ivan madero
ivan madero

Reputation: 26

My first recommendation is to not access directly to the database, as could lead into different errors and also in a DC instance with different nodes, the information obtained couldn't be always 100% true.

Upvotes: 0

Related Questions