JavaScript in WEBCON
Designer Studio allows you to switch the Form rules editor to the JavaScript expression editor mode. In this mode a rule is defined as a JavaScript script that uses the JavaScript API functions provided by WEBCON, instead of being built from blocks in the visual editor.
JavaScript scripts are used, among other things, to change form field values, to manage the visibility, editability and requirement of form fields, to control the appearance of the form and to provide additional validation conditions. Like other form rules, scripts are executed in the user's browser as a result of specific events – e.g. when the form page loads or after a form field value changes. A script can be typed manually or built from ready-made elements available in the side panel of the editor, grouped by functionality.
Switching the edit mode
The edit mode is set in the Rule configuration panel. To switch a rule to JavaScript mode:
- Open the Rule configuration panel – with the Configuration button in the top right corner of the rule editing area or with the Open configuration in the side panel command in the rule menu on the form rule list.
- On the Basic tab, expand the Edit mode list and select JavaScript mode.
| Edit mode | Description |
|---|---|
| Form rule | The rule is built from blocks in the visual editor. This is the default mode. |
| JavaScript mode | The rule is defined as a JavaScript script in the JavaScript expression editor. |
After the mode is changed, the configuration panel is replaced with the Properties side panel containing the elements available in JavaScript mode (see Side panel).
JavaScript mode can be selected both for form rules defined in a process or globally and for rules defined directly where they are used – e.g. in the Form rule executed on page load option in the Form configuration panel. In the latter case the editor is opened with the Open the expression editor button, and the Rule configuration panel displayed after clicking Configuration contains only the Edit mode field.
The Form rule and JavaScript mode edit modes work independently. Changing the mode – in either direction – does not transform the existing expression but clears the current content of the rule without any warning. If the mode was changed by mistake, the rule content can be restored with the Undo last action button on the top bar of Designer Studio.
JavaScript expression editor
In JavaScript mode the rule editing area works like a code editor – the script is typed directly with the keyboard and the JavaScript syntax is highlighted. As in the visual mode, a path indicating the edited rule is displayed above the editing area, and the Properties side panel is shown on the right.

To insert an element from the side panel into the script, place the cursor in the appropriate place of the script and then double-click the element in the panel or drag it to the editing area. A ready-made code fragment is inserted – e.g. a function call with sample arguments – which can then be modified.
Configuration objects, such as form fields, paths or rules, are inserted into the script as tags with the object name (e.g. Notes). Thanks to this, you only need to know the name of a form field to refer to it – when the rule is executed, the tag is replaced with the appropriate reference to the object. Tags can be moved within the script and deleted like regular text.
Compared to the Form rule mode, the editor in JavaScript mode differs as follows:
- the Operations tab is not available in the side panel – arithmetic, logical and comparison operators are typed directly in JavaScript syntax,
- the Ctrl + Space shortcut does not display the list of suggestions and the @ character does not start the object search – elements are inserted from the side panel,
- the Fit to screen, Zoom out and Zoom in buttons are not displayed in the editing area.
The other elements of the editor work the same as in the visual mode – the Close the side panel / Open the side panel button hides and shows the side panel again, the Configuration button opens the Rule configuration panel, and the Testing button in the bottom left corner displays a bar with the Element ID field and the Preview button.
The editor does not validate JavaScript syntax. An error in the script – e.g. a missing bracket or a wrong number of function arguments – will only surface when the rule is executed on the form. It is therefore worth checking how the rule works on the form before publishing the changes.
Example
The following rule hides the Notes field if the form is displayed on a mobile device:
if (G_ISMOBILE) {
HideField('[Notes]');
}
To build it, type the if statement and then insert from the Functions tab of the side panel:
- the condition – the Is this a mobile device? item from the JavaScript functions › Global group,
- the instruction hiding the field – the Notes item from the JavaScript functions › Hide group.
The saved process rule can then be run in a selected place of the configuration – e.g. by inserting it into the rule executed on page load from the Process form rules group on the Functions tab (see WEBCON functions).
Side panel
In JavaScript mode the side panel is called Properties. The elements that can be inserted into the script are grouped on tabs, and the Search field is displayed above the element tree.
| Tab | Content |
|---|---|
| Functions | WEBCON functions that allow you to invoke other form rules, open and start workflow instances, move an instance along a path and run menu actions (see WEBCON functions), and the JavaScript functions group with ready-made code fragments (see JavaScript functions). |
| Values | Global constants, process constants and performance indicators. |
| Objects | Identifiers of configuration objects – e.g. global form fields, applications and processes, data sources, business entities and form rules. For form fields, child items with their ID and database field name are also available, used as arguments of some functions. |
| Parameters | Rule parameters. If the rule has no parameters, the No parameters defined message is displayed. |
Form fields and context variables, available on the Values tab in the visual mode, are inserted in JavaScript mode with the functions from the JavaScript functions group – e.g. Get, Set or Global.
WEBCON functions
The top level of the Functions tab contains groups of functions related directly to workflows and workflow instances. In the Inserted code column, object tags are marked with a name in square brackets, e.g. [Rule] – in the editor they are displayed as tags with the object name.
| Group | Inserted code | Description |
|---|---|---|
| Process form rules | InvokeRule([Rule]) | Invokes the selected form rule defined in the current process. The group contains all form rules of the process. |
| Global form rules | InvokeRule([Rule]) | Invokes the selected global form rule. The group contains all form rules defined globally in the system. |
| Global business rules | [Rule] | Inserts the selected global business rule into the script. The group is available in the global form rule editor. |
| Hyperlinks | see the table below | Functions that start a new or open an existing workflow instance and return the Portal address. |
| Move next step (workflow - step) | MoveToNextStep([Path]) | Moves the workflow instance along the selected path to the next step. Paths are grouped by the workflows and steps they start from. |
| Invoke menu action (workflow - step) | InvokeMenuAction([Button]) | Runs the action triggered by the selected menu button. Buttons are grouped by workflows (Global menu) and steps. |
Functions of the Hyperlinks group:
| Item | Inserted code | Description |
|---|---|---|
| Portal Address | GetPortalAddress() | Returns the Portal address, e.g. https://intranet.webcon.com/PORTAL/. It allows you to dynamically create links to Portal elements such as reports or dashboards. |
| StartElement | StartElement(workflowID, formID, 'AttText1=' + encodeURIComponent('WEBCON') + '&AttText2=' + encodeURIComponent('BPS')) | Starts a new workflow instance with the specified workflow ID (workflowID) and form type ID (formID). The last, optional argument allows you to pass parameters, e.g. values to fill in the fields of the new form. |
| StartElementInNewWindow | StartElementInNewWindow(workflowID, formID, '…') | Works like StartElement but opens the new instance in a new browser window. |
| OpenElement | OpenElement(elementID, '…') | Opens an existing workflow instance with the specified ID (elementID). The last, optional argument allows you to pass parameters. |
| OpenElementInNewWindow | OpenElementInNewWindow(elementID, '…') | Works like OpenElement but opens the instance in a new browser window. |
JavaScript functions
The JavaScript functions group contains ready-made code fragments grouped by functionality. Groups related to form fields (Set, Get, Hide, etc.) display the list of form fields – the code is inserted for the form field selected from the list, and its form depends on the form field type. The content of groups related to item lists, form field groups, tab panels or OAuth authentication depends on the elements defined in the process – if the process has no such form fields, the group is empty.
In the Inserted code column, the form field tag is marked in square brackets, e.g. [Field].
Set
Functions that assign a value to a form field.
| Form field type | Inserted code |
|---|---|
| Text (e.g. Text, Multiple lines of text) | SetValue('[Field]', 'tekst'); |
| Floating-point number | SetTypedValue('[Field]', { value: 123.45 }); |
| Date and time | SetValue('[Field]', new Date(2010, 0, 30, 13, 45)); |
| Choice field | SetValue('[Field]', 'wartość'); |
| Person or group | SetValue('[Field]', 'domena\\login#Nazwa'); |
Get
Functions that return the value of a form field.
| Item | Inserted code | Description |
|---|---|---|
| Form field | GetValue('[Field]') | Returns the value of a text field, choice field, date, etc. |
| Floating-point number form field | GetTypedValue('[Field]').value | Returns the numeric value of the form field. |
| Form field › ID | GetPairID(GetValue('[Field]')); | For choice fields and person or group fields – returns the ID of the selected value. |
| Form field › Name | GetPairName(GetValue('[Field]')); | For choice fields and person or group fields – returns the name of the selected value. |
Hide and Show
The Hide group contains functions that hide form elements, and the Show group – functions that display elements hidden earlier.
| Item | Hide | Show |
|---|---|---|
| Form field | HideField('[Field]'); | ShowField('[Field]'); |
| Comments | HideComment(); | ShowComment(); |
If item lists, tab panels or OAuth authentication form fields are defined in the process, the groups also contain functions that hide and show these elements – e.g. the item list control (HideSubelementControl / ShowSubelementControl), an item list column (HideSubelementColumn / ShowSubelementColumn), item list and item list row buttons, a tab panel (HideTab / ShowTab) or the OAuth authentication control (HideOAuthControl / ShowOAuthControl).
Disable and Enable
| Group | Inserted code | Description |
|---|---|---|
| Disable | DisableControl('[Field]'); | Disables the form field control – the field value cannot be edited on the form. |
| Enable | EnableControl('[Field]'); | Enables a form field control disabled earlier. |
Mark as required and Mark as not required
| Group | Inserted code | Description |
|---|---|---|
| Mark as required | MarkRequired('[Field]'); | Marks the form field as required. |
| Mark as not required | MarkNotRequired('[Field]'); | Marks the form field as not required. |
For item list columns, the groups contain the MarkSubelementRequired and MarkSubelementNotRequired functions respectively.
Collapse and Expand
| Group | Inserted code | Description |
|---|---|---|
| Collapse | CollapseGroup([Group]) | Collapses the selected form field group – only the group name is displayed on the form. |
| Expand | ExpandGroup([Group]) | Expands a form field group collapsed earlier. |
Global
Variables and functions that return information about the context in which the form is displayed. For items returned in the "ID#Name" format, child items are available that use the GetPairID and GetPairName functions to return only the ID or only the name.
| Item | Inserted code | Description |
|---|---|---|
| Application | G_APP | Application in the "ID#Name" format. |
| Process | G_PROC | Process in the "ID#Name" format. |
| Workflow | G_WF | Workflow in the "ID#Name" format. |
| Form type | G_DOCTYPE | Form type in the "ID#Name" format. |
| Current step | G_WFSTEP | The step the workflow instance is in, in the "ID#Name" format. |
| Business entity | G_COM | Business entity in the "ID#Name" format. |
| Logged on user | G_CURUSER | The logged-in user in the "domain\login#Name" format. |
| Document - instance number | G_WFELEM | Workflow instance in the "ID#Signature" format. |
| Document - Parent instance number | G_WFELEM_PARENT | Parent workflow instance in the "ID#Signature" format. |
| Is admin mode active? | G_ADMINMODE | Returns true if the form is displayed in admin mode. |
| Do I have permission to edit? | G_EDITMODE | Returns true if the user has permissions to edit the instance. |
| Is edit mode active? | G_ISCHECKOUT | Returns true if the form is displayed in edit mode. |
| Is this a mobile device? | G_ISMOBILE | Returns true if the form is displayed on a mobile device. |
| Is this a compact form? | G_ISCOMPACT | Returns true if the form is displayed in compact mode. |
| Is this a new instance? | G_ISNEW | Returns true if the workflow instance has not been saved yet. |
| Set window/banner title | SetFormTitle('') | Sets the text passed as the argument in place of the instance signature and in the browser tab title, e.g. SetFormTitle('New registration form'). |
| Set banner subtitle | SetFormSubtitle('') | Sets the subtitle in the form banner, e.g. SetFormSubtitle('Form for IT Department employees'). |
System
| Item | Inserted code | Description |
|---|---|---|
| Validate and convert to floating point | ConvertStringToFloat('10.10') | Converts text to a floating-point number. |
| Validate floating point and return text with comma as decimal separator | ConvertFloatToString(10.1010, 2) | Converts a floating-point number to text with a decimal comma; the second argument specifies the number of decimal places. |
| Convert text to date | StringToDate('2010-01-01') | Converts text to a date. |
| Convert date to text in 'pl' or 'en-us' format | DateToString(new Date(), 'pl') | Converts a date to text in the Polish format ('pl', e.g. "2023-09-14") or the US format ('en', e.g. "9/14/2023"). |
| Convert date to string formatted as [yyyy-mm-dd] | DateToString(new Date()) | Converts a date to text in the yyyy-mm-dd format. |
| Enable view | EnableRootPanel(); | Unlocks the main view of the form. |
| Disable view | DisableRootPanel(); | Locks the main view of the form. |
Item List
Functions that operate only on Item list form fields. The group contains the item lists defined in the process.
| Function | Description |
|---|---|
SubelementHasRows([List]) | Returns true if at least one row has been added to the item list. |
SubelementCountRows([List]) | Returns the number of item list rows. |
SubelementInitialization([List]) | Fills the item list again with the values set in its configuration. The function does not work in the final step. |
SubelementDelete([List], 1) | Deletes the item list row with the specified number (numbering starts from 1). |
DeleteSubelementRows([List], [1, 2, 3]) | Deletes the item list rows with the specified numbers. |
SubelementDelete([List]) | Deletes all item list rows. |
Tab Panel
| Function | Description |
|---|---|
SelectTab([Panel]) | Sets the selected tab as the one currently displayed on the form. |
Attachments
| Item | Inserted code | Description |
|---|---|---|
| Attachment count | G_ATTCOUNT | Returns the number of attachments added to the workflow instance. |
| Check if attachment with extension "pdf" exists | CheckIfAttExists('[.]pdf$') | Returns true if there is an attachment whose name matches the given regular expression – in this case a file with the .pdf extension. |
| Check if attachment "file.pdf" exists | CheckIfAttExists('^file[.]pdf$') | Returns true if there is an attachment with the specified name. |
OAuth
Functions that operate on OAuth2 authentication form fields. Each item contains the list of such form fields defined in the process.
| Item | Function | Description |
|---|---|---|
| Authenticate | Authenticate([Field]) | Starts authentication with the OAuth2 provider specified in the form field configuration. |
| Is Authenticated | IsAuthenticated([Field]) | Returns true if the user has been authenticated. |
| Get token | GetToken([Field]) | Returns the access token issued during authentication. |
QR Scan
| Item | Inserted code | Description |
|---|---|---|
| Show QR scan | ShowQrButton('[Field]'); | Displays the QR code scan button in the form field control. |
| Hide QR scan | HideQrButton('[Field]'); | Hides the QR code scan button in the form field control. |
| Scan QR | ScanQRValue('[Field]'); | Starts scanning a QR code and inserts the read value into the form field. |