Copying information to the clipboard - copytoclipboard


JavaScript can be used to send information from the Swift MEAP™ application to the iOS clipboard.  This allows users to paste values into other applications / email clients / messaging, if data needs to be submitted by the user in another application.

Any information read by a JavaScript is inserted to the clipboard using a custom action: copytoclipboard

Only iOS devices are supported, Android devices will not support the copy to clipboard action


The action command to send data to the clipboard is:

\"action\":\"copytoclipboard\",\"value\":\"some text \"

The above example will insert the value "some text" to the clipboard, to be pasted into other applications.  The copytoclipboard action is only available in the following javascript code:

Supported scripts for copytoclipboard

onSave -  whenever a user saves a record, certain information from that record (or related records) is inserted to the clipboard.

onCustomAction -  create a custom action which is available for selection from a drop down menu of custom actions. 

onQuickAction - for the QuickAction buttons in modules, to launch specific JavaScript code

 

Sample usage

The following example uses the Contacts module (Module id 2) and when the user clicks the custom action button, the contact's First Name and Last Name are copied to the clipboard, from the current record.  We are also formatting the results

We first perform a select query to read the data from the current record that we want to pass to the clipboard (CONTFIRSTNAME and CONTLASTNAME fields from module 2) and launch the "copyNow" function.

In the "copyNow" code, we set the first name to a variable - fname with the description "First Name = " before it, we also set the last name to a variable - lname.  lname also has "Last Name = " at the beginning of the variable.

We then push the contents to the clipboard using the copytoclipboard function.  We define the values that we wish to send.  In the example given, we are inserting a linebreak between the first and last name with a \n parameter.

The complete code example with header and footer information is as follows:

<html><head><title>Swift MEAP CopyToClipboard Script</title><script type="text/javascript">
function onCustomAction()
{
return "[{\"action\":\"select\",\"invoke\":\"copyNow\",\"parameters\":[{\"modulefields\":[{\"module\":\"2\",\"fields\":\"CONTFIRSTNAME,CONTLASTNAME\" }],\"filter\":\"2.uid=$2.uid\"}]}]";
}
function copyNow(row1)
{
var fname = "First Name = "+row1[0]._2.CONTFIRSTNAME;
var lname = "Last Name = "+row1[0]._2.CONTLASTNAME;
return "[{\"action\":\"copytoclipboard\",\"value\":\"" + fname + "\\n" + lname + "\"}]";
}
</script></head><body></Body></html>

 

The above code, would copy the following to the clipboard (we will assume that the name of the user is John Smith):

 

First Name = John

Last Name = Smith