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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Can not compile a scripted job on Confluence

Hello Community,

I'm writing to you as I have an issue on a job on Confluence.
My usecase : send automatically a Confluence page by email with the current Week number into the object.

Here is my code (ScriptRunner job) :

// Confluence imports
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.mail.Email
import com.atlassian.mail.server.SMTPMailServer
import com.atlassian.confluence.mail.ConfluenceMailServerManager
import java.util.Calendar
   public static final int WEEKS = Calendar.WEEK_OF_YEAR

// Get Week number
def week = WEEKS

// Mail
def subject = "subject W${week}"
def body = "body"
def emailAddr = "email"

def sendEmail(String emailAddr, String subject, String body) {
def confluenceMailServerManager = ComponentLocator.getComponent(ConfluenceMailServerManager)
SMTPMailServer mailServer = confluenceMailServerManager.getDefaultSMTPMailServer();
    if (mailServer) {
        Email email = new Email(emailAddr);
    } else {
        // Error to get the mail server from Confluence configuration :
        throw new RuntimeException("no mail server!");
sendEmail(emailAddr, subject, body)

But the script can not be compiled, as I have this issue :

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script1434.groovy: 16: Modifier 'public' not allowed here.
 @ line 16, column 4.
      public static final int WEEKS = Calendar.WEEK_OF_YEAR

Script1434.groovy: 16: Modifier 'static' not allowed here.
 @ line 16, column 4.
      public static final int WEEKS = Calendar.WEEK_OF_YEAR

Does anyone have any idea why I can not compile ?
Thanks for any help !

1 answer

1 accepted

1 vote
Answer accepted

If it's saying "not allowed here", I'm going to go on a limb and say - try removing it.


Indeed, but when I remove :

public static final int WEEKS = Calendar.WEEK_OF_YEAR

The Week number I have in the subject is not good ("3" instead of current 31) :(

Well, that is working as intended. Calendar.WEEK_OF_YEAR is just a static integer used for getters and setters. In other words, Calendar as class itself does not have any idea what date and time it is, until you construct it.


You need to first create a Calendar instance (unless specified then by default that's the current date), and then you can get the week number from it, like so:

Calendar calendar = Calendar.getInstance(Locale.ITALY); 

int weekOfYear = calendar.get(Calendar.WEEK_OF_YEAR);

java.util.Calendar itself is older and most tutorials will recommend to use more modern stuff, but it will get the job done just fine for what you are using it.

I didn't expect such a quick answer !
Now I fully understand where my issuecame from, when I use :

Calendar calendar = Calendar.getInstance(Locale.FRANCE)
int week = calendar.get(Calendar.WEEK_OF_YEAR)

It works perfectly.
Thank you very much for taking time to reply, it's greatly appreciated.

See you soon on the Community !

Suggest an answer

Log in or Sign up to answer

Atlassian Community Events