Custom Function

Translations of this page:

This is an old revision of the document!

A function is the code block behind a task. It's very simple to create a new function because a function is defined as simple Java interface:
public interface IFunction 
     * The current workflow step.
     * @return The current workflow step.
    public IWorkflowStep getWorkflowStep();
     * Initializes the function.
     * @param pWorkflow the current workflow step
    public void init(IWorkflowStep pWorkflow);
     * Runs the function.
     * If the function returns true, the function is fully done, and the workflow jumps to the next step.
     * In case there are more then one next steps, the finish function of IWorkflowStep has to be called.
     * An exception will be thrown otherwise.
     * If finish is already called, it does not matter whether true or false is returned.
     * @return true, if the function is done.
     * @throws Throwable if function fails.
    public boolean run() throws Throwable;
     * Notifies, that the workflow is cancelled.
     * @throws Throwable if canceling fails.
    public void cancel() throws Throwable;

The interface already has an abstract implementation and so it's really super simple to create a new function. Our example will send an email, so it't the EmailFunction:
public class EmailFunction extends AbstractFunction 
    public boolean run() throws Throwable 
        XmlNode smtp = getApplicationZone().getConfig().getNode("/application/mail/smtp");
        if (smtp == null) 
            throw new IllegalArgumentException("SMTP config not found in config (path /application/mail/smtp)!");
        String host = smtp.getNodeValue("host");
        String port = smtp.getNodeValue("port");
        String username = smtp.getNodeValue("username");
        String password = smtp.getNodeValue("password");
        boolean tlsEnabled = Boolean.parseBoolean(smtp.getNodeValue("tlsenabled"));
        String defaultsender = smtp.getNodeValue("defaultsender");
        String from = getNotNullEvaluatedParameter("From");
        String to = getNotNullEvaluatedParameter("To");
        String cC = getEvaluatedParameter("CC");
        String bCC = getEvaluatedParameter("BCC");
        String subject = getNotNullEvaluatedParameter("Subject");
        String body = getEvaluatedParameter("Body");
        log("Mailserver: " + host + ":" + port + "/" + username);
        Mail mail = new Mail(host, port, username, password);
        mail.send(CommonUtil.nvl(from, defaultsender), to, cC, bCC, subject, body, null, null);
        log("From: " + CommonUtil.nvl(from, defaultsender));
        log("To: " + to);
        log("Subject: " + subject);
        return true;

The implementation is straight forward. It extends the AbstractFunction and implements run method. The email settings will be read from the application configuration and the email settings will be read from the input parameters. Finally, the email will be sent.

But there's still one open question: How do we define the input parameters?

Simply use the Functions screen and enter all required information:

That's it. Start using you new function.

This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information