Scope
This document highlights the helper apis used in Smartflow form scripts with examples.
...
You can obtain the control id of a form control in the form builder.
Go to User settings and enable Developer options.
Open the form template in the builder.
Hover over the form control and click on Properties icon to open the properties window of the control.
Click on the Information tab in the properties window.
The text mentioned under Field id is the control identifier of the control.
Index
The index of a form control refers to the row number of the control in a multi-row structure. This property is relevant only if the form control being referred to resides inside a group control.
...
It is important to note that a callback function is executed if and when the current function completes. Since it is asynchronous, the browser engine does not wait for the current function and proceeds with the next code in the sequence.
Category | Function Name | Description |
---|---|---|
DOM access | Returns the value of a form control. | |
Returns the text shown on a form control. | ||
DOM manipulation | Adds a new row in a group control. | |
Removes all existing rows from a group control. | ||
Makes the current form readonly. | ||
Returns the reference to a form control. | ||
Hides action buttons from a group control. | ||
Loads a lazy loaded group control. | ||
Binds a function to an event on a form control. | ||
Binds a function to an event on a group control. | ||
Removes a row at the mentioned index from a group control. | ||
Saves the current form. | ||
Sets the provided value to a form control. | ||
Sets the provided value to a form control (only if the field is empty). | ||
Renders the standard form status selection popup. | ||
Context variables | Returns the name of the domain that the user is currently logged in to. | |
Returns the properties of the user who is currently logged in. | ||
Returns the mode in which the digital form is open. | ||
Returns the form status of the current form. | ||
Returns the current locale code in use. | ||
Returns the name of the platform in which the app is currently running. | ||
Sets the status of the current form. | ||
Sets the current locale in use. | ||
Functions | Checks whether the search value is present in the provided collection. | |
System actions | Requests the server for a system action like send an email or create a report. | |
Requests the server to generate a report of a form. | ||
Requests the server to send an email. |
sfSetValidationBool(value)
...
Description: cancels the form and navigates to the previous page. If the form has autosave enabled and isn’t disabled:
If save callback is overridden then it calls the save callback function.
Else, it validates the form and saves it if validation is successful, otherwise, it gives validation error message
Info |
---|
Example: sfRedirect() |
sfSelect(source, filters, fields, parameters, callBack)
Parameters: source, filters, fields, parameters, callBack
...
source(string): the entities that needs to be selected that is Form or Dataset
...
( |
...
) |
...
{
“Id”: “EntitiesId”,
“FieldsFilter”:”{FieldName}=='value'”,
}
fields(string and optional): the fields that are to be selected separated by comma.
Parameters(string and optional):the value for the placeholders used in virtual query.
callBack(function): The callback function that will be called after select is successful.
Returns(object/array of object): Form or Dataset values
Code Block |
---|
sfSelect('FORM', {
'Name' : 'Timesheet',
'include' : 'Data',
'FieldsFilter': "{ProjectNumber} == 'PRJ-001' && {Date} == '2022-07-01'"
}, "", "", function(results) {
if(getPlatform() == "browser"){
if (results && results.length > 0) {
// Forms found. Do something
} else {
// No forms found
}
} else {
if (results && results.length > 0 && results[0].Data ) {
// Records found. Do something
} else {
// No forms found
}
}
}); |
Code Block |
---|
sfSelect('Dataset', {
"Id": "e54a5505-58c0-49df-8b0b-8e62e9c05aaa",
"FieldsFilter": "{QRCode} == 'SJG872JK'",
"OrderBy": "InspectionDate desc"
}, "", "", function(results) {
var data = getPlatform() == "browser" ? results.Data : results[0].Data; // Remember this is impacted if we use the ID of the dataset vs name
if (data && data.length > 0) {
// Records found. Do something
} else {
// No record found
}
}); |
...
title | Example |
---|
sfSelect('Dataset',{
'Id':'56EECA2D-5912-4B71-BDA8-D428BB0158CF',
“FieldsFilter”:”'{Name} !== ‘Tesla’”
},’’,'',function(res){
...
});
Return Object For Browser:
{
"DatasetId": "56EECA2D-5912-4B71-BDA8-D428BB0158CF",
"Name": "Test Dataset",
"DisplayFieldName": "Name",
"KeyFieldName": "Code",
"Distribution": null,
"SyncToTablet": "true",
"Configuration": null,
"Type": "CUSTOM",
"SourceType": "Standard",
"Priority": "High",
"TranslationCode": null,
"RefExternal": "Test Dataset",
"DateCreated": "2020-03-31T15:32:11.81Z",
"DateModified": "2020-04-20T11:15:39.87Z",
"TranslationText": null,
"RuntimeReference": "2_1_Datasets_20200420111539774",
"IsMasterData": "false",
"DeleteExpiredItems": null,
"Data": [{
"DatasetItemId": "1245E017-BH87-4992-9C9D-79EB5A66A161",
"Code": "1",
"Name": "ABC",
"SortOrder": "1",
"EndDate": null,
"RefExternal": null,
"TranslationCode": null,
"TranslationText": null,
"DateCreated": "2020-03-31T15:33:43.16Z",
"DateModified": "2020-03-31T15:33:43.207Z",
"RuntimeReference": "2_1_Datasets_20200331153342906"
}, {
"DatasetItemId": "80116330-FG3F-4787-94EF-9341292EB889",
"Code": "2",
"Name": "XYZ",
"SortOrder": "2",
"EndDate": null,
"RefExternal": null,
"TranslationCode": null,
"TranslationText": null,
"DateCreated": "2020-03-31T15:33:43.16Z",
"DateModified": "2020-03-31T15:33:43.207Z",
"RuntimeReference": "2_1_Datasets_20200331153342906"
}]
}
Return Array of Object for App:
[{
"DatasetId": "56EECA2D-5912-4B71-BDA8-D428BB0158CF",
"Name": "Test Dataset",
"DisplayFieldName": "Name",
"KeyFieldName": "Code",
"Distribution": null,
"SyncToTablet": "true",
"Configuration": null,
"Type": "CUSTOM",
"SourceType": "Standard",
"Priority": "High",
"TranslationCode": null,
"RefExternal": "Test Dataset",
"DateCreated": "2020-03-31T15:32:11.81Z",
"DateModified": "2020-04-20T11:15:39.87Z",
"TranslationText": null,
"RuntimeReference": "2_1_Datasets_20200420111539774",
"IsMasterData": "false",
"DeleteExpiredItems": null,
"Data": [{
"DatasetItemId": "1245E017-BH87-4992-9C9D-79EB5A66A161",
"Code": "1",
"Name": "ABC",
"SortOrder": "1",
"EndDate": null,
"RefExternal": null,
"TranslationCode": null,
"TranslationText": null,
"DateCreated": "2020-03-31T15:33:43.16Z",
"DateModified": "2020-03-31T15:33:43.207Z",
"RuntimeReference": "2_1_Datasets_20200331153342906"
}, {
"DatasetItemId": "80116330-FG3F-4787-94EF-9341292EB889",
"Code": "2",
"Name": "XYZ",
"SortOrder": "2",
"EndDate": null,
"RefExternal": null,
"TranslationCode": null,
"TranslationText": null,
"DateCreated": "2020-03-31T15:33:43.16Z",
"DateModified": "2020-03-31T15:33:43.207Z",
"RuntimeReference": "2_1_Datasets_20200331153342906"
}]
...
sfInsert(source, dataObject, callback)
...
sfOpenAttachment(fileName)
Note: Not working in the browser at the moment as 0 is passed as formId.
Parameters: fileName
fileName(string): the name of the form file that is to be opened
...
Note |
---|
It is advised not to use the functions listed below as they will be deprecated soon. |
Function usage | Deprecation plan | Proposed alternative in 8.2 |
---|---|---|
sfGetCurrentUser(“Roles”) | Will return a comma separated list of roles that the currently logged in user has (instead of a json string) | |
sfGetCurrentUser(“UserGroups”) | To be deprecated | sfGetCurrentUser(“UserGroup”) |
sfCheckUserHasRole | Not to be supported further but may continue to work for near future. | sfContains(sfGetCurrentUser("Roles"),"<RoleToCheck>"); |
sfChangeLanguage | Not to be supported further but may continue to work for near future. | sfSetLocale(“<LanguageCode>”) |
sfGetDocumentMode() | Will return “web” in browser (instead of “mobile”) | |
sfSendEmail | FORM_FILES_PDF and FORM_DOCUMENT_WITH_CHILDREN to be deprecated as attachmentTypes | FORM_DOCUMENT, FORM_FILES can be used instead of FORM_FILES_PDF |
sfCreateDocument | To be deprecated | sfAddSystemTriggerAction |
sfGetCurrentUserId | Not to be supported further but may continue to work for near future. | sfGetCurrentUser(“Id”) |
sfSetCurrentUser | To be deprecated as the changes are not saved on the server. |