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);
email.setSubject(subject);
email.setBody(body);
mailServer.send(email);
} 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 !