Add a script and expose its output

This task adds the Run Script node that scores each candidate. The score becomes an output that the decision in Add a decision routes on.

process flows add script expose its output 1

For how a script reads and writes the process flow’s data, and the Code Snippets it starts from, see How data moves through a process flow.

Prerequisites

Procedure

  1. In the Script Editor, create a server script.

  2. Right-click the script and select Code Snippets. Under functions > p9 > processFlow, select getData to insert the read-data snippet.

  3. Adapt the snippet to score the candidate: read the candidate from globals, compute a score, and return it with result:

    // Score a candidate application.
    const data = p9.processFlow.getData()
    const candidate = data.globals.candidate
    const years = Number(candidate.yearsOfExperience) || 0
    
    let score = 0
    if (years >= 8) {
      score = 90
    } else if (years >= 4) {
      score = 70
    } else {
      score = 40
    }
    
    result = { data: { score } }
  4. Open the process flow on the canvas.

  5. Drag a Run Script node onto the canvas, and connect the Start event to it.

  6. Select the Run Script node to open its details.

  7. In Step name, enter a meaningful name, for example Score application.

  8. Select the script you created in the Script Editor.

  9. On the Outputs panel, select Generate Outputs.

    Result: The score is exposed as a property that later steps can read.

process flows add script expose its output 2

Results

  • The process flow scores each candidate.

  • The score is available to later steps as an output, for example {Outputs>/<activity>/score}, where <activity> is this node’s identifier. See Binding syntax reference.

Next steps