Hi,
how to get current user id in groovy or how to pass run parameter value to groovy?
please find below my example logic and I want it something similar to below:
In the below example I would like to get the current user id through groovy plugin, then based on that, will execute the SQL query to get department of the logged in person, later check for the department using IF condition and value is true then display the links accordingly.
import com.atlassian.renderer.v2.RenderMode
def renderMode = RenderMode.suppress(RenderMode.F_FIRST_PARA)
def userSql = "select dept from users table where user ='\$current_user_id'"
def userMacro = "{sql-query:datasource=testDS|table=false} ${userSql} {sql-query}"
def userdept = subRenderer.render(userMacro, context, renderMode)
if(userdept == 'sales'){
def dept="<a href="gotosales">Sales</a>"
}else if(userdept == 'sales'){
def dept="<a href="gotomanager">manager</a>"
}else{
## do nothing
}
out.println(dept)
Here I'm attaching the screen shot for better understanding, please find that and let me know how to get it fixed.
Out put:
Thanks alot.
I found the answer, create a RUN macro.
First parameter of the RUN should be hidden with any value, and second parameter should contain the current logged in user id, find the example below
{run:replace=g1::hidden value:Hidden description:hidden, g2:$current_user_id:User
Then write groovy script inside RUN macro, like below
import org.apache.commons.lang.StringEscapeUtils; import com.atlassian.renderer.v2.RenderMode def renderMode = RenderMode.suppress(RenderMode.F_FIRST_PARA) def choiceSql = "select dept from AC_users where ad_user='$g2'" def choiceMacro = "{sql-query:datasource=testDS|table=false} ${choiceSql} {sql-query}" def choices = subRenderer.render(choiceMacro, context, renderMode) if(choices == 'Design'){ link = "<a href='http://gmail.com'>Design</a>" } out.println link
But I'm unable convert <a href tag into link ant its displaying as it is.
Please clarify your question. Are you talking about JIRA or Confluence? You have mentioned both in the labels. Remove the labels that don't apply.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For Confluence, Pre-defined variables describes the run variables available including user based variables.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can get the ApplicationUser object for the currently logged in user with something like this:
def
currentUser = ComponentAccessor.getJiraAuthenticationContext().getUser()
Then you should be able to call that object's getKey() method.
https://docs.atlassian.com/jira/latest/com/atlassian/jira/user/ApplicationUser.html
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.