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

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

Rian Rian September 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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

7 votes
Answer accepted
David at David Simpson Apps
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
September 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 September 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 at David Simpson Apps
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
September 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 September 26, 2011

Thanks, David, this help a lot.

0 votes
Martin Cleaver
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 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?
0 votes
Anh Mather September 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 September 26, 2011

Thanks, Anh. This did the trick.

Rian Rian September 26, 2011

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

Rian Rian September 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?

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events