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

using currentuser in database pickup confuration script is not working

mohammad moeini
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 26, 2023

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'

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 26, 2023

Hi @mohammad 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

TAGS
AUG Leaders

Atlassian Community Events