Parsware
All articles

Process design

Process variables

A process carries values from one step to the next: what the manager decided, how many days were asked for. Each is a variable, declared once on the process with a name and a type, given a first value in On start, and read and written by name. We added one to the Leave Approval sample and misspelt another on purpose.

The process's Variables in the properties panel: approved, Yes / No, and days with its type list open, next to the title "Process variables"

A record holds what a request is: the dates, the employee, the reason. A process also needs to remember things about this run: what the manager decided, whether finance has seen it, how many times it's been sent back. Those are variables.

We used the Leave Approval sample from samples/solutions/bpms-leave-approval-process again. Open its process and select the process itself, Leave Approval at the top of the outline.

Declaring one

Under Variables in the properties panel, the sample declares one:

The process's Variables: approved, Yes / No, with Add variable under it, and the three Events below: On start Written, On complete and On cancel Nothing written

approved, a Yes / No. Review Request sets it, and the branch after it reads it.

Select Add variable, give it a name and pick its type. There are four:

A second variable, days, with its type list open: Text, Number, Yes / No, Date

We added days, a Number. The trash can at the end of a row removes it.

The name is what scripts write, so treat it as fixed. Renaming a variable doesn't rewrite the scripts that use it. A row with no name isn't offered anywhere, and the problems panel reports it.

A first value: On start

A variable has no value until something gives it one. The process's own On start, under Events, runs once when a run begins. The sample uses it for exactly that:

The code page for Leave Approval, On start: setVariable("approved", false);

setVariable("approved", false);

That way the branch never finds approved empty, even if it's asked before anyone has decided.

Reading and writing

Two functions, anywhere a script runs:

  • getVariable("approved") reads it.
  • setVariable("approved", true) changes it, and it stays changed for the rest of the run.

A branch condition may only read, so it's offered getVariable and not setVariable. A step's events, like Review Request's On complete, may do both.

Type getVariable(" and the editor offers the names you've declared:

On start, line 2: getVariable(" with completion offering getVariable("approved") boolean, What Review Request decided, and getVariable("days")

approved also shows its type and a description, which the sample's process file gives it: What Review Request decided. Seeded false on start, so the branch is never asked before there is an answer.

A misspelt name

We changed On start to set "aproved", with one p, and closed the code page. The bar in the corner of the canvas now says 1 problem:

The designer with the problems list open: Leave Approval — On start uses a variable called "aproved", which this process does not declare.

Without the panel, the run would have set a variable nobody reads, and the branch would have read approved as false forever. Select the line and the designer takes you to the process, where On start is.

That line used to read onStart reads a variable called "aproved": the slot's internal name, always in English, and "reads" about a line that writes. It now names the process and the slot the way the code list does, in your language.

Variables, as the process stores them

Variables are a list in the process document, each with a name, a type and, ideally, a description:

"variables": [
  { "id": "var-approved", "name": "approved", "type": "boolean",
    "description": "What Review Request decided. Seeded false on start, so the branch is never asked before there is an answer." }
]

The description is what completion shows beside the name, so it is worth writing for the next maker: what sets it, what reads it, and what value it starts with. The parallel sign-off sample declares four, and every one says where its value comes from:

"variables": [
  { "name": "refused", "type": "boolean", "description": "Set true by whichever side refuses." },
  { "name": "finance_note", "type": "text", "description": "What Finance wrote on their coform, carried across by writesVariable with no script at all." },
  { "name": "legal_note", "type": "text", "description": "The same, from Legal." },
  { "name": "answered_by", "type": "list", "description": "Who answered, gathered after the join." }
]

A variable filled with no code

finance_note shows the shortest way to fill a variable: a coform field can write straight into one when the person finishes the task. The field names the variable it writes, and the value lands there without a line of script. Later steps read it with getVariable("finance_note"), for example to copy it onto the purchase order. Coforms: a form for a task shows how a coform field is set up.

Variable or record field?

Both hold a value; they answer different questions.

Keep it in When Example
A field on the record It is part of what the record is, and people should see it after the run The decision, the approver's note
A process variable It only matters to how this run proceeds approved, while the branch decides; how many times it was sent back

A good habit, which every sample here follows: decisions end up on the record, because the record outlives the run, and reports, views and audits read records. Variables carry what the process needs on the way there.

How far a variable reaches

  • The whole run. Every step of a run sees the same variables, and a value set in one step is there in all the later ones.
  • Every route after a fork. A variable set on Finance's route is seen on Legal's, which is how refused works. Record references, by contrast, are kept per route; Fork and join explains the difference.
  • Not across a call. A step that calls another process doesn't share its variables. Records cross a call; variables stay with their own process, so neither becomes part of the other's contract. Task types covers calls.

Naming variables

  • Name the question, not the step: approved, refused, days. A variable called step3result means nothing a month later.
  • Lower case, words joined by underscores: finance_note. It matches how the samples write them and reads well in code.
  • One meaning each. If approved is sometimes the manager's decision and sometimes the director's, make two variables.
  • Seed every one a branch reads, in On start.

Questions that come up

Can I change a variable's type later? You can, in the list, but scripts that set it keep writing what they wrote. Check each setVariable for it afterwards.

Do variables survive a published new version? A run keeps the version it started on, with its variables. A new version's variables apply to runs started after you publish.

Can a report read a variable? Reports read records. If people need to see a value after the run, put it on the record.

Try it

Declare days as a Number and add this line to Submit Request's On complete, which already has code of its own:

setVariable("days", getRecord("par_leaverequest", getRecordRef("record")).par_days);

par_days is the request's Days field. A later step can then read how many days were asked for without opening the record again.

Next: the problems panel: everything it checks, and how it takes you to the fix.