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

Dummy's Use of Macros

Deleted user September 7, 2019

I want to find a way of using a macro from (https://community.atlassian.com/t5/Confluence-questions/How-to-evaluate-values-on-Confluence-Page/qaq-p/331934#M56003).  I don't know anything about macros.

I have created a macro in Confluence called datecountdown and copied the script into it. 

When I add it to a page I get:

"<div class="aui-message info shadowed"> <p>Countdown until <strong>Feb 29, 2020: 173 days 8 hours 36 minutes 20 seconds</strong></p> </div>" rather than the number of days.

I don't know how to write macros, is there something simple a dumb user can do to add a macro to a page?

Help appreciated.

 

2 answers

2 accepted

1 vote
Answer accepted
DPKJ
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 7, 2019

I am modifying this to just print number if days, hours and minutes,

## Macro title: Date Countdown
## Macro has a body: No
## Body processing: No macro body
##
## Developed by: Remo Siegwart
## Date created: 14/04/2012
## This user macro counts down the number of days until a specific date
## @param endDate:title=End Date|type=date|required=true|desc=The end date. Format: mm/dd/YYYY
## declare variables and initialize as java date objects with current date
#set ( $endDate = $content.currentDate )
#set ( $currentDate = $content.currentDate )
## parse endDate param to milliseconds and set as time of endDate variable
$endDate.setTime($content.currentDate.parse($paramendDate))
## now we have 2 valid java date objects to work with
#if($currentDate.before($endDate))
## currentDate is before endDate =&gt; calculate deltas
#set( $delta =  ($endDate.getTime() - $currentDate.getTime()) / 1000)
## calculate remaining seconds
#set( $deltaSeconds = $delta % 60 )
#set( $delta =  $delta / 60 )
## calculate remaining minutes
#set( $deltaMinutes = $delta % 60 )
#set( $delta =  $delta / 60 )
## calculate remaining hours
#set( $deltaHours = $delta % 24 )
#set( $delta =  $delta / 24 )
## calculate remaining days
#set( $deltaDays = $delta % 365 )

&lt;div class="aui-message info shadowed"&gt;
  &lt;p&gt;Countdown until &lt;strong&gt;$deltaDays days $deltaHours hours $deltaMinutes minutes&lt;/strong&gt;&lt;/p&gt;
&lt;/div&gt;
#else
## currentDate is after endDate
&lt;div class="aui-message success shadowed"&gt;
  &lt;p&gt;Countdown to &lt;strong&gt;$action.dateFormatter.format($endDate)&lt;/strong&gt; expired &lt;strong&gt;$generalUtil.getRelativeTime($endDate)&lt;/strong&gt;!&lt;/p&gt;
&lt;/div&gt;
#end
DPKJ
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 7, 2019

Macro in Confluence are similar to Macro in word or excel.

Confluence provide some built-in macro, if these Macro doen't suffice our need we can create User Macro which provide little bit of programming, and if we want full control we can Java Macro code using Java API and plugin model provided my Confluence.

Deepanshu Natani
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 9, 2019

@[deleted]I think you should accept this answer by @DPKJ . You have currently accepted your own answer :-)

0 votes
Answer accepted
Deleted user September 8, 2019

Thanks, but neither response answers my question.  I don't have the time to learn how to write macros, I just want to use that one to show the number of days until a date on my page.  The one above simply gives me a piece of HTML, not a number.

DPKJ
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 8, 2019

I have updated given HTML and it is just a number now,

## Macro title: Date Countdown
## Macro has a body: No
## Body processing: No macro body
##
## Developed by: Remo Siegwart
## Date created: 14/04/2012
## This user macro counts down the number of days until a specific date
## @param endDate:title=End Date|type=date|required=true|desc=The end date. Format: mm/dd/YYYY
## declare variables and initialize as java date objects with current date
#set ( $endDate = $content.currentDate )
#set ( $currentDate = $content.currentDate )
## parse endDate param to milliseconds and set as time of endDate variable
$endDate.setTime($content.currentDate.parse($paramendDate))
## now we have 2 valid java date objects to work with
#if($currentDate.before($endDate))
## currentDate is before endDate =&gt; calculate deltas
#set( $delta =  ($endDate.getTime() - $currentDate.getTime()) / 1000)
## calculate remaining days
#set( $deltaDays = $delta % 365 )

$deltaDays
#end

 

Deleted user September 8, 2019

Brilliant, thank you, it now gives a number - but unfortunately an incorrect one.  With and end date of 28th Feb 2020 it should give 172 days from 9th Sept,  but it gives a different number every time I load the page.

DPKJ
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 8, 2019

@[deleted]My mistake, try this

## Macro title: Date Countdown
## Macro has a body: No
## Body processing: No macro body
##
## Developed by: Remo Siegwart
## Date created: 14/04/2012
## This user macro counts down the number of days until a specific date
## @param endDate:title=End Date|type=date|required=true|desc=The end date. Format: mm/dd/YYYY
## declare variables and initialize as java date objects with current date
#set ( $endDate = $content.currentDate )
#set ( $currentDate = $content.currentDate )
## parse endDate param to milliseconds and set as time of endDate variable
$endDate.setTime($content.currentDate.parse($paramendDate))
## now we have 2 valid java date objects to work with
#if($currentDate.before($endDate))
## currentDate is before endDate =&gt; calculate deltas
#set( $delta =  ($endDate.getTime() - $currentDate.getTime()) / 1000)
## calculate remaining seconds

#set( $delta =  $delta / 60 )
#set( $delta =  $delta / 60 )
#set( $delta =  $delta / 24 )
## calculate remaining days #set( $deltaDays = $delta % 365 ) $deltaDays #end
Like Vitor LC likes this
Deleted user September 8, 2019

Fantastic, thank you very much.  Appreciated!

Jason Teo October 31, 2019

Hi all,

 

I totally understand how Ormond feels and what he is getting at. I am do not have much macro knowledge as well but i there is so much needed to be done on confluence which the functions are not available.

@DPKJyou mentioned that Confluence provide some built-in macros. Can i know where can i find them?

Is there any references or documentations which a newbie macro user like me can refer to when writing a macro or to learn how to write a macro?

DPKJ
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 31, 2019

@Jason_TeoEverything that is not plain text is kind of a Macro in Confluence.

Macro can be as simple as banner, side-bar etc and as complex as fetching data from external source and displaying on Confluence page.

So, if you are getting started with Confluence, read this - https://confluence.atlassian.com/doc/get-started-777010817.html

And also watch this webinar - https://www.youtube.com/watch?v=y1YTsMTrC7c

if you want to build a Macro, you have two options,

  1. User defined Macro (the macro discussed in this thread is of this type)
  2. Developer Macro Module (you need Java and plugin development knowledge for this)
Jason Teo October 31, 2019

@DPKJThanks for all the reference. I will definitely take a look :)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events