Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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. 

  1. Go to User settings and enable Developer options.

  2. Open the form template in the builder.

  3. Hover over the form control and click on Properties icon to open the properties window of the control.

  4. Click on the Information tab in the properties window.

  5. 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

sfGetValue

Returns the value of a form control.

sfGetText

Returns the text shown on a form control.

DOM manipulation

sfAddGroupitems

Adds a new row in a group control.

sfClearGroup

Removes all existing rows from a group control.

sfDisableForm

Makes the current form readonly.

sfField

Returns the reference to a form control.

sfHideGroupButtons

Hides action buttons from a group control.

sfLoadGroup

Loads a lazy loaded group control.

sfRegisterFieldCallback

Binds a function to an event on a form control.

sfRegisterGroupCallback

Binds a function to an event on a group control.

sfRemoveGroupItems

Removes a row at the mentioned index from a group control.

sfSaveForm

Saves the current form.

sfSetValue

Sets the provided value to a form control.

sfSetDefaultValue

Sets the provided value to a form control (only if the field is empty).

sfShowFormStatusPopup

Renders the standard form status selection popup.

Context variables

sfGetCurrentDomain

Returns the name of the domain that the user is currently logged in to.

sfGetCurrentUser

Returns the properties of the user who is currently logged in.

sfGetDocumentMode

Returns the mode in which the digital form is open.

sfGetFormStatus

Returns the form status of the current form.

sfGetLocale

Returns the current locale code in use.

sfGetPlatform

Returns the name of the platform in which the app is currently running.

sfSetFormStatus

Sets the status of the current form.

sfSetLocale

Sets the current locale in use.

Functions

sfContains

Checks whether the search value is present in the provided collection.

System actions

sfAddSystemTriggerAction

Requests the server for a system action like send an email or create a report.

sfCreateDocument

Requests the server to generate a report of a form.

sfSendEmail

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:

  1. If save callback is overridden then it calls the save callback function.

  2. 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
  	}
});

...

titleExample

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.