Class ScriptTask

All Implemented Interfaces:
HasHandlers
Direct Known Subclasses:
StartProcessTask

public class ScriptTask extends Task
Task that executes arbitrary code, either synchronous or asynchronous. Override the execute() method to provide custom logic.
See Also:
  • Constructor Details

  • Method Details

    • getOrCreateRef

      public static ScriptTask getOrCreateRef(JavaScriptObject jsObj)
    • create

      public JavaScriptObject create()
      Overrides:
      create in class Task
    • setDataSources

      public ScriptTask setDataSources(String dataSources) throws IllegalStateException
      Comma-separated list of DataSource IDs to pre-load into the server-side scripting context before this task executes. The listed DataSources become available as DataSource instances and same-named local variables.

      This is the task-level equivalent of OperationBinding.dataSources and Process.dataSources; it scopes the pre-load to a single ScriptTask rather than the entire operationBinding or process.

      DataSources already listed on the operationBinding or process do not need to be repeated here.

      Parameters:
      dataSources - New dataSources value. Default value is null
      Returns:
      ScriptTask instance, for chaining setter calls
      Throws:
      IllegalStateException - this property cannot be changed after the underlying component has been created
      See Also:
    • getDataSources

      public String getDataSources()
      Comma-separated list of DataSource IDs to pre-load into the server-side scripting context before this task executes. The listed DataSources become available as DataSource instances and same-named local variables.

      This is the task-level equivalent of OperationBinding.dataSources and Process.dataSources; it scopes the pre-load to a single ScriptTask rather than the entire operationBinding or process.

      DataSources already listed on the operationBinding or process do not need to be repeated here.

      Returns:
      Current dataSources value. Default value is null
      See Also:
    • setIsAsync

      public ScriptTask setIsAsync(Boolean isAsync) throws IllegalStateException
      Whether the script task is asynchronous. A synchronous task is expected to return data directly from execute() and is considered complete once the execute() method exits.

      An asynchronous task is expected to start processing in execute(), and will not be considered complete setOutput() is called.

      Parameters:
      isAsync - New isAsync value. Default value is false
      Returns:
      ScriptTask instance, for chaining setter calls
      Throws:
      IllegalStateException - this property cannot be changed after the underlying component has been created
    • getIsAsync

      public Boolean getIsAsync()
      Whether the script task is asynchronous. A synchronous task is expected to return data directly from execute() and is considered complete once the execute() method exits.

      An asynchronous task is expected to start processing in execute(), and will not be considered complete setOutput() is called.

      Returns:
      Current isAsync value. Default value is false
    • setLanguage

      public ScriptTask setLanguage(String language) throws IllegalStateException
      Scripting language for the execute() body. When running inside an OperationBinding.process, this controls which script engine evaluates the code:
      • null or "graal.js" (default) — execute in the current GraalJS server context, with full access to Smart GWT APIs and Process.state
      • Any other value (e.g. "groovy") — delegate to the JSR-223 ScriptEngine registered under that name. The engine receives these bindings: dsRequest, criteria, values, oldValues, session, config, and processState (the Process.state map)

      This attribute has no effect in client-side workflows.

      Parameters:
      language - New language value. Default value is null
      Returns:
      ScriptTask instance, for chaining setter calls
      Throws:
      IllegalStateException - this property cannot be changed after the underlying component has been created
      See Also:
    • getLanguage

      public String getLanguage()
      Scripting language for the execute() body. When running inside an OperationBinding.process, this controls which script engine evaluates the code:
      • null or "graal.js" (default) — execute in the current GraalJS server context, with full access to Smart GWT APIs and Process.state
      • Any other value (e.g. "groovy") — delegate to the JSR-223 ScriptEngine registered under that name. The engine receives these bindings: dsRequest, criteria, values, oldValues, session, config, and processState (the Process.state map)

      This attribute has no effect in client-side workflows.

      Returns:
      Current language value. Default value is null
      See Also:
    • setPassThruOutput

      public ScriptTask setPassThruOutput(Boolean passThruOutput) throws IllegalStateException
      Does this processElement pass through output from the last executed task (i.e. transient state)?

      See taskInputExpressions for details on the transient state outputs.

      Note that this property does not affect the task at all but is an indicator to the user and to the workflow editor of the behavior of the task as coded (See Process.passThruTaskOutput()).

      Overrides:
      setPassThruOutput in class ProcessElement
      Parameters:
      passThruOutput - New passThruOutput value. Default value is false
      Returns:
      ScriptTask instance, for chaining setter calls
      Throws:
      IllegalStateException - this property cannot be changed after the underlying component has been created
    • getPassThruOutput

      public Boolean getPassThruOutput()
      Does this processElement pass through output from the last executed task (i.e. transient state)?

      See taskInputExpressions for details on the transient state outputs.

      Note that this property does not affect the task at all but is an indicator to the user and to the workflow editor of the behavior of the task as coded (See Process.passThruTaskOutput()).

      Overrides:
      getPassThruOutput in class ProcessElement
      Returns:
      Current passThruOutput value. Default value is false
    • execute

      public Object execute(Object input, Record inputRecord)
      Execute the task. The return value, if not undefined, will be written as the output.

      For an asynchronous task, the return value is ignored and the task should call setOutput() to continue the process with the next task.

      Parameters:
      input - the task input
      inputRecord - the task input record if inputs is specified. See TaskIO
      Returns:
      the task output. For multiple field output, call setOutput() instead, and return null
    • setOutput

      public void setOutput()
      Sets the task output available to the next task via Process.getLastTaskOutput() or more commonly, with a TaskInputExpression property. If outputFieldList is specified, the output will also be written to the specified fields in the process state (See TaskIO).

      To have the output written as-is to the process state, see bindOutput.

      NOTE: for an asynchronous task, calling setOutput() indicates the task is complete.

      See Also:
    • setOutput

      public void setOutput(Object output)
      Sets the task output available to the next task via Process.getLastTaskOutput() or more commonly, with a TaskInputExpression property. If outputFieldList is specified, the output will also be written to the specified fields in the process state (See TaskIO).

      To have the output written as-is to the process state, see bindOutput.

      NOTE: for an asynchronous task, calling setOutput() indicates the task is complete.

      Overrides:
      setOutput in class Task
      Parameters:
      output - output record to provide to the next task
      See Also:
    • setOutputData

      public void setOutputData(Object taskOutput)
      Set the task output as specified by outputField.

      NOTE: for an asychronous task, calling setOutputData() indicates the task is complete. For a task with multiple outputs, call ScriptTask.setOutputRecord instead.

      Parameters:
      taskOutput - task output
    • onInit_ScriptTask

      protected void onInit_ScriptTask()
    • onInit

      protected void onInit()
      Overrides:
      onInit in class ProcessElement