Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
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

Macro for creating event from a meeting notes page

Edited

It would be nice to create events in Team Calendar from within a page in Confluence where you plan your meeting.

To achieve this, create a new macro with this code:

#set ($D='$')

 

<script type="text/javascript">

        $(document).ready(function() {

            $('#submitevent').click(  function () {

                 

                var row = AJS.$('.plugin-tabmeta-details table th:contains("startDate")').parent();

                var startDate =  AJS.$('td', row).text().replace( /(\d+) (\w+) (\d{4})[^d]+/, "$2 $1, $3");

                row = AJS.$('.plugin-tabmeta-details table th:contains("calendar")').parent();

                var calendar =  AJS.$('td', row).text();

                row = AJS.$('.plugin-tabmeta-details table th:contains("startTime")').parent();

                var startTime =  AJS.$('td', row).text();

                row = AJS.$('.plugin-tabmeta-details table th:contains("endTime")').parent();

                var endTime =  AJS.$('td', row).text();

                row = AJS.$('.plugin-tabmeta-details table th:contains("where")').parent();

                var where = AJS.$('td', row).text();

                 

                 

                #set ($persons="")

                #set ($datahtml = $renderContext.getEntity().getBodyAsString())

                #foreach ($stringList in $datahtml.split("ri:userkey=\""))

                    #if ($stringList.matches("\w+\".*"))

                        #set ($userkey=$stringList.substring(0,$stringList.indexOf('"')))

                        #if ($persons.length()>0)

                            #set ($persons=$persons+", ")

                        #end

                        #set ($persons=$persons+"'"+$userkey+"'")

                    #end

                #end

                console.log(calendar+" "+startDate+" "+startTime+" "+endTime+" "+where+" "+$persons);

                 

                 ${D}.ajax({

                    url: 'https://YOURCONFLUENCEURL/rest/calendar-services/1.0/calendar/events.json',    //Your api url

                    type: 'PUT',   //type is any HTTP method

                    data: {

                        originalSubCalendarId:'',

                        originalStartDate:'',

                        subCalendarId:calendar,

                        uid:'',

                        eventType:'other',

                        originalEventType:'',

                        customEventTypeId:'',

                        originalCustomEventTypeId:'',

                        childSubCalendarId:'',

                        what:'Fridays Meeting',

                        person:[$persons],

                        startDate:startDate,

                        startTime:startTime,

                        endDate:startDate,

                        endTime:endTime,

                        allDayEvent:false,

                        freq:'',

                        byday:'',

                        interval:1,

                        until:'',

                        repeatEnds:false,

                        recurrenceId:'',

                        editAllInRecurrenceSeries:false,

                        where:where,

                        url:window.location.href,

                        description:'',

                        userTimeZoneId: 'Asia/Yekaterinburg'

                    },      //Data as js object

                    success: function () {

                        $('.eventcreationresults').html(startDate+" "+startTime+" created!");

                    }

                });

            });

 

              

             

        });

    </script>

<form>

    <div class="eventcreationresults">...</div>

    <input id="submitevent" type="button"  value="Create Event">

</form>

 Second, amend the template of your meeting notes so it has Page Properties with such fields (values are for example):

Набросок[1].png

Also, add the macros created before.

You need to get the correct calendar id. Just click your calendar name and copy the id from URL field of a browser:

Набросок (1).png

 

Now everything should work. Just create a new meeting, insert some values in the Page Properties form, save the page and you will see a button "Create Event". Press it once and check if an event appears in the calendar.

Current limitations:

  • The script doesn't check if the event is already created, nor it updates the created event.
  • If your event starts at 11:00 and ends at 12:00, type 11:00 AM and 12:00 PM, otherwise it would produce an error "The event ends earlier than starts".
  • Macro doesn't report any errors.

 

Feel free to improve the macro, but please copy me with your updates so I could also use them :)

Thank you.

1 comment

Do you have an example of what the actual call looks like?  I cannot get the APIU to accept a post.

Comment

Log in or Sign up to comment
TAGS
Community showcase
Published in Bitbucket

⭐ Calling all Bitbucket and DevOps experts: Special showcase opportunity ⭐

Hi, Bitbucket community! Are you a DevOps practitioner (or know one in your network)? Do you have DevOps tips, tricks, or learnings you'd like to share with the community? If so, we'd love to hea...

38 views 3 1
Read article

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