ResetFields property

ServerRelayButton.ResetFields — Logical

Special value available in formulas:

Item

ServerRelayButton

The button this property is part of, enabling multiple checked items in the app designer to share the same formula and be updated all at once.

Consider the fields Field1 and Field2, which should only be considered to be valid if their values are greater than 4. Without using the Item value, the Valid property of Field1 would need to use the formula Field1 > 4Field1 > 4 and the Valid property of Field2 would need to use the formula Field2 > 4Field2 > 4.

Using Item, both formulas can read Item > 4Item > 4. This is useful if you have many fields and you want to be able to update their formulas all at once. To do so, click their check boxes in Calcapp Creator and make sure that a checked field is selected. Then, when you update a formula for one checked field, you update all the other checked fields too, which is a great timesaver.

Use Item in exactly the same way you'd use the regular name. Button1.VisibleButton1,Visible and Item.VisibleItem,Visible are equivalent, for instance.

Whether fields are reset after they have been successfully sent. When a field is reset, its value is set to the initial value.

Assigning a blank value to a field

Out of the box, server relay buttons can only reset field values to their initial values, and not to a blank value. To do so, you need to use a formula button, which runs custom formulas you associate with its OnPress property.

This OnPress formula sends the values of Field1 and Field2 to the address https://hooks.example.com/123:

RELAY({ Field1, Field2 }, "https://hooks.example.com/123")RELAY({ Field1; Field2 }; "https://hooks.example.com/123")

The RESET function is used to reset fields to their initial values, whereas RESET.BLANK sets field values to a blank value. This formula sends field values and then immediately sets them to blank values:

RELAY({ Field1, Field2 }, "https://hooks.example.com/123"); RESET.BLANK({ Field1, Field2 })RELAY({ Field1; Field2 }; "https://hooks.example.com/123");; RESET.BLANK({ Field1; Field2 })

(;;; in the formula above is used to separate different parts of the formula that is run.)

With the formula above, field values are reset immediately after the data is sent. If the data can't be sent successfully, which can happen if there is a network problem, the fields are reset regardless.

To wait for RELAY to successfully send its data before resetting the field values, use the AWAIT function:

AWAIT(RELAY({ Field1, Field2 }, "https://hooks.example.com/123"), RESET.BLANK({ Field1, Field2 }))AWAIT(RELAY({ Field1; Field2 }; "https://hooks.example.com/123"); RESET.BLANK({ Field1; Field2 }))

The formula fragment given as the second parameter to AWAIT is run when the action given as the first parameter has run to completion, that is, when RELAY has successfully sent the data.

There's just one more thing we can do to improve the formula. The first parameter to RELAY specifies what fields to send, and this entire parameter needs to be repeated verbatim when provided to RESET.BLANK. If you need to include many fields, that makes the formula unnecessarily long and hard to read.

The LET function allows us to assign names to values. Here is the formula above, rewritten to use LET:

LET(Fields := { Field1, Field2 }, AWAIT(RELAY(Fields, "https://hooks.example.com/123"), RESET.BLANK(Fields)))LET(Fields := { Field1; Field2 }; AWAIT(RELAY(Fields; "https://hooks.example.com/123"); RESET.BLANK(Fields)))

Above, the { Field1, Field2 }{ Field1; Field2 } formula fragment has been given the name Fields, and can be referenced by simply typing this name in the formula.

Examples

ResetSwitchFieldResetSwitchField

Makes a server relay button reset the fields it has sent after the data has been sent, only if ResetSwitchField is toggled to its "on" position.

RELAY({ App }, "https://hooks.example.com/123", ResetFields: ResetSwitchField)RELAY({ App }; "https://hooks.example.com/123"; ResetFields: ResetSwitchField)

This formula is associated with the OnPress property of a formula button, and sends data when the button is pressed. All fields of the app are sent, courtesy of the { App }{ App } parameter. The sent fields are reset when the report has been successfully sent only if ResetSwitchField is toggled to its "on" position.

RELAY({ App }, "https://hooks.example.com/123"); RESET({ App })RELAY({ App }; "https://hooks.example.com/123");; RESET({ App })

This formula is associated with the OnPress property of a formula button, and sends data when the button is pressed, immediately followed by all fields being reset. All fields of the app are considered, courtesy of the { App }{ App } parameter.

AWAIT(RELAY({ App }, "https://hooks.example.com/123"), RESET({ App }))AWAIT(RELAY({ App }; "https://hooks.example.com/123"); RESET({ App }))

This formula is associated with the OnPress property of a formula button, and sends data when the button is pressed. All fields are also reset, but only once the data has been successfully sent. All fields of the app are considered, courtesy of the { App }{ App } parameter.

LET(Fields := { Field1, Field2 }, AWAIT(RELAY(Fields, "https://hooks.example.com/123"), RESET(Fields)))LET(Fields := { Field1; Field2 }; AWAIT(RELAY(Fields; "https://hooks.example.com/123"); RESET(Fields)))

This formula is associated with the OnPress property of a formula button, and sends data when the button is pressed. All fields are also reset, but only once the data has been successfully sent. Only the fields Field1 and Field2 are considered. LET is used to assign a temporary name to { Field1, Field2 }{ Field1; Field2 }, saving us from having to repeat these field names elsewhere in the formula.