It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

NEED example of a user macro that retrieves the current username from the context

Rian Rian Sep 22, 2011

I see many of snippets and sample expressions tossed around on this site, but no single coherent example for a non-programmer like myself.

I just want a user macro that will return the current username (not the full name). I want to feed this in to an sql query that will pull information about this user out of a local database.

Come on, easy points for some advanced technician out there! Thanks, R.M.

P.S. Extra points (unofficially) for pointers to some documentation that would show me how to do this myself.

4 answers

1 accepted

7 votes
Answer accepted
David Simpson Community Leader Sep 22, 2011
Here's a user macro called {my-username} it should be self evident I hope
## Macro title: my-username
## Macro has a body: N
## Body processing: Selected body processing option
## Output: Selected output option
##
## Developed by: My Name
## Date created: dd/mm/yyyy
## Installed by: My Name
$action.remoteUser.name
Avinash Sep 13, 2012

Hi, Can i get sample code for displaying current date? I've tried $getDateFormat() and other stuff but it doesnt work! May be im missing something....

Thanks,

Avinash

2 votes
David Simpson Community Leader Sep 22, 2011

To find out which Java objects are exposed in velocity and thus help you with writing your own user macro, I'd recommend:
https://developer.atlassian.com/display/CONFDEV/Confluence+Objects+Accessible+From+Velocity

Rian Rian Sep 26, 2011

Thanks, David, this help a lot.

0 votes
Anh Mather Sep 22, 2011

{tip:title=this works for me}

Current user fullname: {user-info:fullname}

Current userid: {user-info:username}

{tip}
You can pass it to a variable in groovy:
{groovy:output=wiki}
mport com.atlassian.confluence.core.ContentEntityObject;
import com.atlassian.confluence.util.GeneralUtil;
import com.atlassian.spring.container.ContainerManager;
import com.atlassian.confluence.pages.Attachment;
import com.atlassian.confluence.pages.AttachmentManager;
import com.atlassian.confluence.util.velocity.VelocityUtils;
import com.atlassian.confluence.web.context.StaticHttpContext;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.*;
import javax.activation.MimetypesFileTypeMap;
import java.util.Date;
def String username = '{user-info:username}'
println("current user : " + username + "\n");
{groovy}
Rian Rian Sep 26, 2011

Thanks, Anh. This did the trick.

Rian Rian Sep 26, 2011

Yes it did! just add another parameter, as in "{user-info:email|user=@self}"

Rian Rian Sep 26, 2011

No it didn't! This returns information about the user that created the page, not the current user. Is there another example that would work?

0 votes
Martin Cleaver Mar 18, 2014
For clarity, this line: def String username = '{user-info:username}' Did not establish the username when groovy ran that line, instead it simply embedded the macro expression verbatim in its stdout. That stdout, when when passed to Confluence, gets treated as content on the page, and Confluence expands it. Or, am I wrong?

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Posted in Featured Groups

Never Not Networking! Share your LinkedIn profile and let's connect.

As suggested on the Friday Funday thread (https://community.atlassian.com/t5/Off-topic-discussions/EARLY-Friday-Fun-for-June-14-Best-advice-you-ever-got-edition/td-p/1105333#U1106280) - and happy bir...

389 views 39 6
View post

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you