sfSetFormStatus

Sets the status of the current form. The changed form status is reflected in the form status popup window when saving the form.

This function merely changes the status of the form in the runtime, and does not push the change to the server. For the changed status to be reflected on the server, the form must be saved. See sfSaveForm.

Syntax

sfSetFormStatus(formStatus, callback, isFormStatusName)

Parameters

Name

Type

Mandatory

Description

Name

Type

Mandatory

Description

formStatus

string

yes

Form status name or System status code to be set for the current form.

If setting the form status by name, then the name provided must match with the unique name of the form status and more importantly, the status must be linked to the form.

If setting the form status by system status code, there must be at least one form status with the mentioned system status.

callback

function

no

Code block to be executed after the form status has been changed.

See callback function.

isFormStatusName

boolean

no

Set true to set the form status by name and false to set the system status.

If no value is passed, it is considered as false and the system status is set.

Usage examples

Example 1

Let us consider an inspection form that can have these statuses (mentioned along with their system status codes) in its workflow:

  • Open (OPEN)

  • MeterReadingSubmitted (OPEN)

  • Reviewed (COMP)

If the form is Open, the status can be changed to MeterReadingSubmitted by,

sfSetFormStatus('MeterReadingSubmitted','',true)

It changes the status of the current form to MeterReadingSubmitted (but the change is not pushed to the server yet).

Example 2

Consider the form in example above. To change the status of the form and save it so that the status change is reflected on the server,

sfSetFormStatus('MeterReadingSubmitted',function(){ // Continue saving the form },true)

Example 3

Consider the form in example above. The form can be set to completed by setting the system status code.

sfSetFormStatus('COMP',function(){ // Continue saving the form })

It sets the current form’s status to Reviewed as this is the status to be set when the form is completed.

It is important to note that if there are multiple form statuses with the same system status code, then the first form status in order will be picked. This example sets the form status to ‘Reviewed’ since there is only one form status that has the system status COMP. However, trying to change the system status to OPEN will set the form status to ‘Open’ and not to ‘MeterReadingSubmitted’ because ‘Open’ is the first form status in order that matches the system status code. Hence, it is advised to use the system status code as the first parameter only when either there is only one form status with the mentioned system status code or the form statuses are configured in the right sort order.