Skip to main content
Version: 2027 R1

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:

  1. 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.
  2. On the Basic tab, expand the Edit mode list and select JavaScript mode.
Rule configuration panel with the Edit mode list expanded and JavaScript mode selected
Edit modeDescription
Form ruleThe rule is built from blocks in the visual editor. This is the default mode.
JavaScript modeThe 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.

caution

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.

JavaScript expression editor with a script hiding the Notes field on mobile devices and the Properties side panel on the Functions tab

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.

tip

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.

TabContent
FunctionsWEBCON 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).
ValuesGlobal constants, process constants and performance indicators.
ObjectsIdentifiers 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.
ParametersRule 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.

GroupInserted codeDescription
Process form rulesInvokeRule([Rule])Invokes the selected form rule defined in the current process. The group contains all form rules of the process.
Global form rulesInvokeRule([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.
Hyperlinkssee the table belowFunctions 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:

ItemInserted codeDescription
Portal AddressGetPortalAddress()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.
StartElementStartElement(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.
StartElementInNewWindowStartElementInNewWindow(workflowID, formID, '…')Works like StartElement but opens the new instance in a new browser window.
OpenElementOpenElement(elementID, '…')Opens an existing workflow instance with the specified ID (elementID). The last, optional argument allows you to pass parameters.
OpenElementInNewWindowOpenElementInNewWindow(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 typeInserted code
Text (e.g. Text, Multiple lines of text)SetValue('[Field]', 'tekst');
Floating-point numberSetTypedValue('[Field]', { value: 123.45 });
Date and timeSetValue('[Field]', new Date(2010, 0, 30, 13, 45));
Choice fieldSetValue('[Field]', 'wartość');
Person or groupSetValue('[Field]', 'domena\\login#Nazwa');

Get​

Functions that return the value of a form field.

ItemInserted codeDescription
Form fieldGetValue('[Field]')Returns the value of a text field, choice field, date, etc.
Floating-point number form fieldGetTypedValue('[Field]').valueReturns the numeric value of the form field.
Form field › IDGetPairID(GetValue('[Field]'));For choice fields and person or group fields – returns the ID of the selected value.
Form field › NameGetPairName(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.

ItemHideShow
Form fieldHideField('[Field]');ShowField('[Field]');
CommentsHideComment();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​

GroupInserted codeDescription
DisableDisableControl('[Field]');Disables the form field control – the field value cannot be edited on the form.
EnableEnableControl('[Field]');Enables a form field control disabled earlier.

Mark as required and Mark as not required​

GroupInserted codeDescription
Mark as requiredMarkRequired('[Field]');Marks the form field as required.
Mark as not requiredMarkNotRequired('[Field]');Marks the form field as not required.

For item list columns, the groups contain the MarkSubelementRequired and MarkSubelementNotRequired functions respectively.

Collapse and Expand​

GroupInserted codeDescription
CollapseCollapseGroup([Group])Collapses the selected form field group – only the group name is displayed on the form.
ExpandExpandGroup([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.

ItemInserted codeDescription
ApplicationG_APPApplication in the "ID#Name" format.
ProcessG_PROCProcess in the "ID#Name" format.
WorkflowG_WFWorkflow in the "ID#Name" format.
Form typeG_DOCTYPEForm type in the "ID#Name" format.
Current stepG_WFSTEPThe step the workflow instance is in, in the "ID#Name" format.
Business entityG_COMBusiness entity in the "ID#Name" format.
Logged on userG_CURUSERThe logged-in user in the "domain\login#Name" format.
Document - instance numberG_WFELEMWorkflow instance in the "ID#Signature" format.
Document - Parent instance numberG_WFELEM_PARENTParent workflow instance in the "ID#Signature" format.
Is admin mode active?G_ADMINMODEReturns true if the form is displayed in admin mode.
Do I have permission to edit?G_EDITMODEReturns true if the user has permissions to edit the instance.
Is edit mode active?G_ISCHECKOUTReturns true if the form is displayed in edit mode.
Is this a mobile device?G_ISMOBILEReturns true if the form is displayed on a mobile device.
Is this a compact form?G_ISCOMPACTReturns true if the form is displayed in compact mode.
Is this a new instance?G_ISNEWReturns true if the workflow instance has not been saved yet.
Set window/banner titleSetFormTitle('')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 subtitleSetFormSubtitle('')Sets the subtitle in the form banner, e.g. SetFormSubtitle('Form for IT Department employees').

System​

ItemInserted codeDescription
Validate and convert to floating pointConvertStringToFloat('10.10')Converts text to a floating-point number.
Validate floating point and return text with comma as decimal separatorConvertFloatToString(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 dateStringToDate('2010-01-01')Converts text to a date.
Convert date to text in 'pl' or 'en-us' formatDateToString(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 viewEnableRootPanel();Unlocks the main view of the form.
Disable viewDisableRootPanel();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.

FunctionDescription
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​

FunctionDescription
SelectTab([Panel])Sets the selected tab as the one currently displayed on the form.

Attachments​

ItemInserted codeDescription
Attachment countG_ATTCOUNTReturns the number of attachments added to the workflow instance.
Check if attachment with extension "pdf" existsCheckIfAttExists('[.]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" existsCheckIfAttExists('^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.

ItemFunctionDescription
AuthenticateAuthenticate([Field])Starts authentication with the OAuth2 provider specified in the form field configuration.
Is AuthenticatedIsAuthenticated([Field])Returns true if the user has been authenticated.
Get tokenGetToken([Field])Returns the access token issued during authentication.

QR Scan​

ItemInserted codeDescription
Show QR scanShowQrButton('[Field]');Displays the QR code scan button in the form field control.
Hide QR scanHideQrButton('[Field]');Hides the QR code scan button in the form field control.
Scan QRScanQRValue('[Field]');Starts scanning a QR code and inserts the read value into the form field.