CLIPBOARDCOPY function

CLIPBOARDCOPY(Text) CLIPBOARDCOPY(Text)

Text

Text

The text string to copy to the clipboard.

Returns

Promise

A promise, which succeeds with no value if the text string is copied successfully and fails otherwise. Pass this promise as the first parameter to AWAIT (and related functions) to take action after the promise has succeeded or failed.

Copies a text string to the clipboard. CLIPBOARDCOPY("Copied!")CLIPBOARDCOPY("Copied!") puts the text string "Copied!" on the clipboard. To copy the value of the text field TextField1, use CLIPBOARDCOPY(TextField1)CLIPBOARDCOPY(TextField1).

This function can only be used from an action formula. It is typically invoked from a formula associated with the OnPress property of a formula button.

If the value to copy is not a text string, convert it first using TOTEXT. These two formulas copy "3.14" and "TRUE", respectively, to the clipboard (provided that the language settings of the app use a decimal point and not a decimal comma):

CLIPBOARDCOPY(TOTEXT(3.14))CLIPBOARDCOPY(TOTEXT(3,14))
CLIPBOARDCOPY(TOTEXT(TRUE))CLIPBOARDCOPY(TOTEXT(TRUE))

To copy the value of the number field NumberField1 to the clipboard, use this formula:

CLIPBOARDCOPY(TOTEXT(NumberField1))CLIPBOARDCOPY(TOTEXT(NumberField1))

TOTEXT does not offer much in the way of customization when converting numbers to text strings. FORMATNUMBER, however, has many such options.

This formula formats the value of NumberField1 with a leading "$" currency symbol and rounds it to two decimal places:

CLIPBOARDCOPY(FORMATNUMBER(NumberField1, 2, 2, LeadingUnit: "$"))CLIPBOARDCOPY(FORMATNUMBER(NumberField1; 2; 2; LeadingUnit: "$"))

Number fields support the FormattedValue property, which returns the value of the field as a formatted text string, using the same settings as when it is displayed in the app.

This formula copies the formatted value to the clipboard:

CLIPBOARDCOPY(NumberField1.FormattedValue)CLIPBOARDCOPY(NumberField1,FormattedValue)

Copying values from embedded apps

An embedded app runs in an iframe on the host page. Many web browsers prevent such apps from copying content to the clipboard.

To fix this issue, add allow="clipboard-write" to the list of attributes for the iframe element:

<iframe seamless
        src="https://connect.calcapp.net/?app=abc123"
        allow="clipboard-write">
</iframe>

Examples

CLIPBOARDCOPY("Copied!")CLIPBOARDCOPY("Copied!")

Copies the text string "Copied!" to the clipboard.

CLIPBOARDCOPY(TextField1)CLIPBOARDCOPY(TextField1)

Copies the value of TextField1 to the clipboard.

CLIPBOARDCOPY(TOTEXT(SwitchField1))CLIPBOARDCOPY(TOTEXT(SwitchField1))

Copies the value of SwitchField1 to the clipboard. TOTEXT must be used when copying values which are not already text strings.

CLIPBOARDCOPY(TOTEXT(NumberField1))CLIPBOARDCOPY(TOTEXT(NumberField1))

Copies the value of NumberField1 to the clipboard. TOTEXT can convert not only logical values to text strings, but also numbers.

CLIPBOARDCOPY(FORMATNUMBER(NumberField1, 1, 4))CLIPBOARDCOPY(FORMATNUMBER(NumberField1; 1; 4))

Copies the value of NumberField1 to the clipboard, rounded to use at least one decimal place and at most four decimal places, depending on the number. FORMATNUMBER provides many more options for formatting numbers than TOTEXT.

CLIPBOARDCOPY(NumberField1.FormattedValue)CLIPBOARDCOPY(NumberField1,FormattedValue)

Copies the value of NumberField1 to the clipboard, formatted with the same settings used when displaying the value in the app.

CLIPBOARDCOPY("Result: " & NEWLINE() & NumberField1)CLIPBOARDCOPY("Result: " & NEWLINE() & NumberField1)

Copies the text string "Result:", followed by a line break and the value of NumberField1, to the clipboard. When joining text strings together with the & operator, TOTEXT is invoked automatically on values which are not text.

AWAIT(CLIPBOARDCOPY(TOTEXT(NumberField1)), BANNER("The value has been copied"))AWAIT(CLIPBOARDCOPY(TOTEXT(NumberField1)); BANNER("The value has been copied"))

Copies the value of NumberField1 to the clipboard. When the copy operation is done, a banner with the text "The value has been copied" is shown using the BANNER function.