Getting started

The Pyrus scripting platform lets users expand the functionality of Pyrus forms to do things like:

  • Automatically calculate and fill in field values based on data entered in other fields.
  • Validate field values.
  • Automatically fill in fields using the form register.

The scripts are written in JavaScript and executed within Pyrus forms. The platform provides a trusted environment to run these scripts and controls their access to your data.

To try out Pyrus scripts, follow these steps:

  • Create a form that contains the fields Start date, End date and Duration. This might be a request form for a business trip or vacation.
  • Open the form’s settings and click on Edit script.
  • Insert the following code into the script editor:
form.onChange(['Start date', 'End date'])
  .setValue('Duration', state => {
    const [startDate, endDate] = state.changes;

    if (!startDate || !startDate.date || !endDate || !endDate.date)
      return null;

    const diff = daysBetween(new Date(startDate.date), new Date(endDate.date));
    return diff + 1;
  });

function daysBetween(d1, d2) {
  const msInDay = 1000 * 60 * 60 * 24;
  return Math.floor((d2.getTime() - d1.getTime()) / msInDay);
}
  • Save your changes.
  • Open a new business trip or vacation request form, then fill in the Start date and End date fields. The Duration field will automatically show the number of days requested:

Was this article helpful?