Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

auto-populating the currentuser name and today's date when creating a new from from a template

Gilbert Louis
Contributor
January 2, 2019

Hi,

Creating my first space template and I'm looking to minimize input fields and so I am looking to automatically populate the 'Requested by' field by the currentusername (registered name of the user creating that new document) AND the created date (today) when a user is creating a new document from that specific template.

Thx for your help

1 answer

0 votes
Diego
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 3, 2019

 

Hello there Gilbert!
You can surely achieve this with native tools from Confluence. However, we will need to dig a little into User Macros creation.

Let us start by taking a look here:

Macro Template Syntax

Writing User Macros

Now for us to achieve this result, we will need to:

1- Click the Cog Icon at the top right corner in Confluence
2- Select General Configuration
3- Search for User Macros in the left side bar
4- Enter User Macros
5- Click to Create a User Macro

Now that we are inside the creation, we can start creating the macro:

1- In the Macro name text field, insert a name for this macro. I used creator-macro, for the sake of simplicity
2- Select who can view this macro under Visibility
3- Write a Macro Title for this macro. Macro title is what is shown when you search for this macro
4- Under Definition of User Macro, look into Macro Body processing
5- Select No Macro Body
6- Now in the Template text field, insert this code for the macro

## @noparams

<div class="aui-message aui-message-info">
$content.getCreatorName()
$action.dateFormatter.formatGivenString("yyyy-MM-dd", $content.getCreationDate())
</div>
7- Save the macro

After saving, you can now create your template and insert this new macro into it. When someone uses the template, their name and content creation date should be displayed.

Let us know if this is what you are looking for!

 

edit: fixed the user macro

Tarun Sapra
Community Champion
January 3, 2019

Hello @Diego

It seems the user @Gilbert Louis is using Confluence cloud, thus I don't think "User macros" are possible on the confluence cloud.

Gilbert Louis
Contributor
January 3, 2019

@Tarun Sapra, @Diego yes we are using confluence cloud.

I have access to the general configuration pages but can only see 'macro usage' option in that list on the left hand side.

I would be surprised that something as 'simple' as fetching the user name to auto-populate it in a user created template is not available in confluence cloud???

or same to fetch today's date to add to my template so I know when that page was created.

Thx

Gilbert

Diego
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 3, 2019

Hello there!

Thanks for pointing that out. I did not notice the tag for Confluence Cloud. I have synced with my Confluence Cloud colleagues about this request and currently, we can not achieve this in Confluence Cloud.

You can surely check this info under Three dots menu (..)>Page Information. A third-party solution does exist, but is only available for Confluence Server as well:

Page Info for ScriptRunner Confluence

Also, let me fix my user macro sent before. Currently, this would show the current user, not the creator. Fixed version is as follows:

## @noparams

<div class="aui-message aui-message-info">
$content.getCreatorName()
$action.dateFormatter.formatGivenString("yyyy-MM-dd", $content.getCreationDate())
</div>

Let us know your thoughts!

Like # people like this
Gilbert Louis
Contributor
January 3, 2019

@DiegoMuch appreciate your time and effort to provide an answer... I will look at implementing in the morning and will let u know... :-)

James Dellow
Community Champion
January 3, 2019

User macros aren't possible in Confluence Cloud, but you can create your own macros (and other functionality) as Confluence Connect apps. The simplest app to create could just be some templated wiki content, accessed as a custom macro (just like a user macro).

More here https://developer.atlassian.com/cloud/confluence/about-confluence-cloud/

Diego
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 4, 2019

Hello there @Gilbert Louis!

As pointed out earlier by Champions here, this solution is not available for Confluence Cloud. The solution provided took in consideration Confluence Server, which is not the correct environment. It may be a good idea to take a look into this article:

Functional differences in Confluence Cloud

You can still check this information under Three dots menu (..)>Page Information. There you should be able to check all those details.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events