JavaScript in BPS
WEBCON BPS Designer Studio has the option to switch the Form rules editor into a JavaScript expression editor mode, which makes creating dynamic scripts much easier with the provided JavaScript API.
JavaScript in WEBCON BPS is used to change form field values, manage their visibility, and provide additional validation conditions. Scripts are run as a response to the defined user behavior in Portal, e.g. when changing the value of a form field, loading a page or as a form of additional validation when selecting a path. The user can enter scripts manually or use the panel of available scripts which are grouped into logical sets that correspond to a specific functionality.
Configuration
1. Form rule edit mode
Option to switch between the two rule edit modes. If JavaScript mode is set, all Dictionary elements will be displayed in JavaScript format when selected.
2. Expression edit area
Area for entering a JavaScript expression.
3. Dictionary of elements for building a script
This panel contains a library of available functions that can be utilized in a script.
An attempt is made to interpret the script.
4. Show
After clicking on this button, a window appears with an preview of the expression entered. If errors occur, the script will not be displayed.
5. Create universal rule
The option is available from the application level. Selecting this option and saving the newly-created rule as a process rule will make it available in the selected process.
6. Switch all editors into advanced mode
Marking the checkbox will display additional columns containing the Variable and Database field that the given function uses.
BPS functions
JavaScript expressions can be built using the elements available by default when creating Business rules or Form rules, such as Values, Objects or Parameters. However, the JavaScript mode also provides functions that refer directly to workflows and workflow instances and allow operations on them.
Process form rules
All form rules defined by the user in the context of the current process are available here. They can be accessed using the function:
InvokeRule(ID)
– invokes a process form rule with the specified ID.
-
Parameters:
ID
– rule identifier in the database. -
Examples of use:
InvokeRule(3231)
Global form rules
All form rules defined globally in the system are available here. They can be accessed using the function:
InvokeRule(ID)
– invokes a global form rule with the specified ID.
-
Parameters:
ID
– rule identifier in the database. -
Examples of use:
InvokeRule(3016)
Hyperlinks
The group of functions that allow workflow instances to be started or opened (in a new browser tab).
StartElement(workflowID, formID, 'queryParameters')
– starts a new workflow instance.
-
Parameters:
workflowID
– workflow identifier in the database.
formID
– form identifier in the database
'queryParameters'
– optional function parameters. -
Examples of use:
StartElement(1208, 6, 'AttText1=' + encodeURIComponent('WEBCON') + '&AttText2=' + encodeURIComponent('BPS'))
– starts a form with an ID of 6 in a workflow whose ID is 1208, where the text fields with the database names "AttText1" and "AttText2" are automatically filled with the values "WEBCON" and "BPS", respectively.
StartElementInNewWindow(workflowID, formID, 'queryParameters')
– starts a new workflow instance in a new browser tab.
-
Parameters:
workflowID
– workflow identifier in the database.
formID
– form identifier in the database
'queryParameters'
– optional function parameters. -
Examples of use:
StartElementInNewWindow(1208, 6, 'AttText1=' + encodeURIComponent('WEBCON') + '&AttText2=' + encodeURIComponent('BPS'))
– starts in a new browser tab and in a workflow whose ID is 1208, a form with an ID of 6, where the text fields with the database names "AttText1" and "AttText2" are automatically filled with the values "WEBCON" and "BPS", respectively.
OpenElement(elementID, 'queryParameters')
– opens a workflow instance.
-
Parameters:
elementID
– instance number.
'queryParameters'
– optional function parameters. -
Examples of use:
OpenElement(2023/01/006, 'AttText1=' + encodeURIComponent('WEBCON') + '&AttText2=' + encodeURIComponent('BPS'))
– opens a form with an instance number of 2023/01/006, where the text fields with the database names "AttText1" and "AttText2" are automatically filled with the values "WEBCON" and "BPS", respectively.
OpenElementInNewWindow(elementID, 'queryParameters')
– opens a workflow instance in a new browser tab.
-
Parameters:
elementID
– instance number.
'queryParameters'
– optional function parameters. -
Examples of use:
OpenElementInNewWindow(2023/01/006, 'AttText1=' + encodeURIComponent('WEBCON') + '&AttText2=' + encodeURIComponent('BPS'))
– opens in a new browser tab a form with an instance number of 2023/01/006, where the text fields with the database names "AttText1" and "AttText2" are automatically filled with the values "WEBCON" and "BPS", respectively.
Move next step
This group includes one function:
MoveToNextStep(pathID)
– makes the workflow instance to go through the specified path to the next step.
-
Parameters:
pathID
– path identifier in the database. -
Examples of use:
MoveToNextStep(1661)
Invoke menu action
This group includes one function:
InvokeMenuAction(buttomID)
– triggers the action defined under the specified menu button.
-
Parameters:
buttonID
– menu button identifier in the database. -
Examples of use:
InvokeMenuAction(152)
Groups of JavaScript functions
Set
The group includes functions for assigning values to form fields and columns of the Item list.
SetTypedValue('Name', {value})
– sets values of the Floating-point number and Data and time form fields.
-
Parameters:
'Name'
– the database name of the form field, i.e. the prefix-free name of the column in the database that contains the form field.
{value}
– the numeric value that will be set for the form field. For dates, include the object class like in the example below. -
Examples of use:
SetTypedValue('AttDateTime1', {value: new Date('2023,0,30,13,45')})
SetTypedValue('AttDecimal1', {value: 123.45})
SetValue('Name','value')
– sets values for text form fields, choice fields, etc.
-
Parameters:
'Name'
– the database name of the form field, i.e. the prefix-free name of the column in the database that contains the form field.
'value'
– a string or text value that will be set for the specified form field. -
Examples of use:
SetValue('AttLong3', 'text')
SetValue('AttChoose1','domain\\login#Name')
SetSubTypedValue(ID, currentRowNumberVariable, 'Name', {value})
– sets the value for the specified row in the Item list column of the Floating-point number and Data and time types.
-
Parameters:
ID
– identifier of the Item list.
currentRowNumberVariable
– number of Item list row (starting from 1).
Name
– the database name of the Item list column, i.e. the prefix-free name of the column in the database that contains the Item list column.
{value}
– the numeric value that will be set in the specified row of the Item list column. For dates, include the object class like in the example below. -
Examples of use:
SetSubTypedValue(4092, 4, 'DET_Value1', { value: 3})
– sets 3 in the column "DET_Value1", row 4 of the Item list whose identifier is 4092.
SetSubTypedValue(4092, 5, 'DET_Att2', {value: new Date(2023,0,30,13,45)})
SetSubValue(ID, currentRowNumberVariable, 'Name','value')
– sets the value for the specified row of the Item list column that is a text field, choice field, etc.
-
Parameters:
ID
– identifier of the Item list.
currentRowNumberVariable
– number of Item list row (starting from 1).
Name
– the database name of the Item list column, i.e. the prefix-free name of the column in the database that contains the Item list column.
'value'
– a string or text value that will be set in the specified row of the Item list column. -
Examples of use:
SetSubValue(4092, 1, 'DET_Att1', 'not applicable')
Get
The group of functions that return the values of the selected form fields / Item list columns, or the identifier or name of the object selected from the form field / Item list column.
GetTypedValue('Name').value
– loads values for the Floating-point number and Data and time form fields.
-
Parameters:
'Name'
– the database name of the form field, i.e. the prefix-free name of the column in the database that contains the form field.
value
– the numeric value loaded for the specified form field. -
Examples of use:
GetTypedValue('AttDateTime1').value
GetTypedValue('AttDecimal1').value
GetValue('Name')
– loads values for text form fields, choice fields, etc.
-
Parameters:
'Name'
– the database name of the form field, i.e. the prefix-free name of the column in the database that contains the form field. -
Examples of use:
GetValue('AttLong3',)
GetValue('AttChoose1')
GetPairID(GetValue('Name'))
– loads the identifier (ID) for text form fields, choice fields, etc.
-
Parameters:
'Name'
– the database name of the form field, i.e. the prefix-free name of the column in the database that contains the form field. -
Examples of use:
GetPairID(GetValue('AttChoose1'))
GetPairID(GetValue('AttInt1'))
GetPairName(GetValue('Name'))
– loads names for text form fields, choice fields, etc.
-
Parameters:
'Name'
– the database name of the form field, i.e. the prefix-free name of the column in the database that contains the form field. -
Examples of use:
GetPairName(GetValue('AttInt3'))
GetPairName(GetValue('AttChoose2'))
GetSubTypedValue(ID, currentRowNumberVariable, 'Name').value
– loads the numeric value from the specified row of the Item list column of the Floating-point number and Data and time types.
-
Parameters:
ID
– identifier of the Item list.
currentRowNumberVariable
– number of Item list row (starting from 1).
'Name'
– the database name of the Item list column, i.e. the prefix-free name of the column in the database that contains the Item list column.
value
– the numeric value that will be loaded from the specified row of the Item list column. -
Examples of use:
GetSubTypedValue(4092, 3, 'DET_Value3').value
GetSubValue(ID, currentRowNumberVariable, 'Name')
– loads the value from the specified Item list column that is a text field, choice field, etc.
-
Parameters:
ID
– identifier of the Item list.
currentRowNumberVariable
– number of Item list row (starting from 1).
'Name'
– the database name of the Item list column, i.e. the prefix-free name of the column in the database that contains the Item list column. -
Examples of use:
GetSubValue(4092, 5, 'DET_Att1')
GetPairID(GetSubValue(ID, currentRowNumberVariable, 'Name'))
– loads the identifier (ID) from the specified Item list column that is a text field, choice field, etc.
-
Parameters:
ID
– identifier of the Item list.
currentRowNumberVariable
– number of Item list row (starting from 1).
'Name'
– the database name of the Item list column, i.e. the prefix-free name of the column in the database that contains the Item list column. -
Examples of use:
GetPairID(GetSubValue(4092, 4, 'DET_Att3'))
GetPairName(GetSubValue(ID, currentRowNumberVariable, 'Name'))
– load the name of the specified row of the Item list column that is a text field, choice field, etc.
-
Parameters:
ID
– identifier of the Item list.
currentRowNumberVariable
– number of Item list row (starting from 1).
'Name'
– the database name of the Item list column, i.e. the prefix-free name of the column in the database that contains the Item list column. -
Examples of use:
GetPairName(GetSubValue(4092, 4, 'DET_Att3'))
Hide
The group of functions that allow you to hide form elements such as: fields, Item lists and their columns, comments, controls.
HideField('Name')
– hides the specified form field.
-
Parameters:
'Name'
– the database name of the form field, i.e. the prefix-free name of the column in the database that contains the form field. -
Examples of use:
HideField('AttChoose4')
HideField('AttDecimal1')
HideSubelementControl(ID)
– hides the specified Item list control.
-
Parameters:
ID
– identifier of the Item list. -
Examples of use:
HideSubelementControl(4092)
HideSubelementColumn(ID, 'Name')
– hides the specified Item list column.
-
Parameters:
ID
– identifier of the Item list.
'Name'
– the database name of the Item list column, i.e. the prefix-free name of the column in the database that contains the Item list column. -
Examples of use:
HideSubelementColumn(4092, 'DET_Value1')
HideComment()
– hides the specified comment on the form. Enter the comment to be hidden in the brackets.
- Examples of use:
HideComment()
HideOAuthControl(ID)
– hides the oAuth authentication control.
-
Parameters:
ID
– form field identifier in the database. -
Examples of use:
HideOAuthControl(4517)
HideTab(ID)
– hides the specified Tab panel on the form.
-
Parameters:
ID
– identifier of the Tab panel in the database. -
Examples of use:
HideTab(4537)
Show
The group of functions that allow you to show form elements such as: fields, Item lists and their columns, comments, controls that were previously hidden.
ShowField('Name')
– shows the specified form field.
-
Parameters:
'Name'
– the database name of the form field, i.e. the prefix-free name of the column in the database that contains the form field. -
Examples of use:
ShowField('AttChoose4');
ShowField('AttDecimal1');
ShowSubelementControl(ID)
– shows the previously hidden Item list column.
-
Parameters:
ID
– identifier of the Item list. -
Examples of use:
ShowSubelementControl(4092)
ShowSubelementColumn(ID, 'Name')
– shows the previously hidden Item list control.
-
Parameters:
ID
– identifier of the Item list.
'Name'
– the database name of the Item list column, i.e. the prefix-free name of the column in the database that contains the Item list column -
Examples of use:
ShowSubelementColumn(4092, 'DET_Att3')
ShowComment()
– shows the previously hidden comment. Enter the comment to be shown in the brackets.
- Examples of use:
ShowComment()
ShowOAuthControl(ID)
– shows the previously hidden control of the oAuth authentication.
-
Parameters:
ID
– form field identifier in the database. -
Examples of use:
ShowOAuthControl(4517)
ShowTab(ID)
– shows the previously hidden Tab panel on the form.
-
Parameters:
ID
– identifier of the Tab panel in the database. -
Examples of use:
ShowTab(4537)
Disable
This group includes one function:
DisableControl('Name')
– disables controls of the selected form fields. Fields locked in this way cannot be edited or changed.
-
Parameters:
'Name'
– the database name of the form field, i.e. the prefix-free name of the column in the database that contains the form field. -
Examples of use:
DisableControl('AttText2Glob')
DisableControl('AttText7')
Enable
This group includes one function:
EnableControl('Name')
– enables controls of the selected form fields.
-
Parameters:
'Name'
– the database name of the form field, i.e. the prefix-free name of the column in the database that contains the form field. -
Examples of use:
EnableControl('AttText2Glob')
EnableControl('AttText7')
Mark as required
The group of functions that allow you to mark the selected form elements as required.
MarkRequired('Name')
– marks the form field as required.
-
Parameters:
'Name'
– the database name of the form field, i.e. the prefix-free name of the column in the database that contains the form field. -
Examples of use:
MarkRequired('AttChoose1')
MarkRequired('AttDateTime2')
MarkSubelementRequired(ID, 'Name')
– marks the Item list column as required.
-
Parameters:
ID
– identifier of the Item list.
'Name'
– the database name of the Item list column, i.e. the prefix-free name of the column in the database that contains the Item list column -
Examples of use:
MarkSubelementRequired(4086, 'DET_Att1')
MarkSubelementRequired(4092, 'DET_Att3')
Mark as not required
The group of functions that allow you to mark the selected form elements as not required.
MarkNotRequired('Name')
– marks the form field as not required.
-
Parameters:
'Name'
– the database name of the form field, i.e. the prefix-free name of the column in the database that contains the form field. -
Examples of use:
MarkNotRequired('AttChoose1')
MarkNotRequired('AttDateTime2')
MarkSubelementNotRequired(ID, 'Name')
– marks the Item list column as not required.
-
Parameters:
ID
– identifier of the Item list.
'Name'
– the database name of the Item list column, i.e. the prefix-free name of the column in the database that contains the Item list column -
Examples of use:
MarkSubelementNotRequired(4086, 'DET_Att1')
MarkSubelementNotRequired(4092, 'DET_Att3')