The currently selected record is generally record, so to delete it you just need to do form.deleteRecord(record).
There are some times this isn’t true, particularly when working with the script editor and link to form fields, but for simple documents it should always be true.
Ok, so I did the video recording and uploaded it to YouTube which walks through creating a new form, creating the script for it, a short diversion to talk about script folder access for scripting, checks out the Word template mentioned above and shows how to grab the template file to populate data from the clipboard.
Here’s the script used in the video:
function Word_Template() {
var first_name_id = 'fld-02f5c873bbdf499595b11624a525d616';
var last_name_id = 'fld-b79a9795b4b4426594be58027c21f9a8';
var prize_id = 'fld-b620679ff7024a309ef67624bb8e5ea0';
var transfer_amount_id = 'fld-30891550250d41d7aa087c87baa7ee9c';
var transfer_method_id = 'fld-3151d0fa67b342f0ad2c9e4bfbc98197';
var address_id = 'fld-b424d8e5a1d041baa91ed2823bcc2727';
var signature_name_id = 'fld-a84db7c9468b41689e6b102938b3c391';
var fieldMap = {
"FirstNamePlaceholder": first_name_id,
"LastNamePlaceholder": last_name_id,
"PrizePlaceholder": prize_id,
"TransferAmount": transfer_amount_id,
"TransferMethod": transfer_method_id,
"AddressPlaceholder": address_id,
"SignatureName": signature_name_id
};
var queryString = Object.keys(fieldMap).map((key) => {
return encodeURIComponent(key) + '=' + encodeURIComponent(record.getFieldValue(fieldMap[key]))
}).join('&');
Utils.copyTextToClipboard(queryString);
Utils.openUrl("file:///Users/pasamio/Library/Containers/com.tapzapp.tapforms-mac/Data/Documents/TFTest.dotm");
}
Word_Template();
Attached is also a copy of the exported Tap Forms archive with the Word Contacts form with Word Template script plus a bonus sample record included. Not the greatest integration point but I think should be more or less functional.
I think if we were on Windows, it’d be a little easier to interact with tooling because you could use COM to invoke an instance of Word and manipulate it more directly, instruct it to save somewhere and then pull the document in. Microsoft’s tooling on the Mac has lagged and one can’t entirely blame them as it is the competition. I’m not aware of any direct mechanism for integrating with Word on Mac which doesn’t require use of either AppleScript or Microsoft’s own Visual Basic for Applications.
Riffing on this, one platform that I have interacted with before is OpenOffice/LibreOffice UNO which allows programatic access to documents stored in it’s format. The downside of this is that you need to ship or have accessible on the network an instance of OpenOffice/LibreOffice to do the heavy lifting (~250MB download vs ~60MB for Tap Forms uncompressed). That would allow the creation of Word documents that could be attached but would obviously require users to download it.
Hi, when I run this script all the records are deleted in that form. I only want to delete the selected record. How can I do that?
Hi, I have been using TF5 for the past 2 months and am really enjoying a lot of the very basic elements making forms. The problem is my knowledge of scripting is zero and so I am very limited with what I can achieve. I have looked online and trawled the forums and it seems its all or nothing, it took me 2 days to find “\r” to add into a script so I could add text to the line below. The next thing is getting information from one form onto another, in my mind that should be relatively easy but I cannot find a basic tutorial on how this is performed, explaining in simple language how this is achieved.The examples don’t have to be complex just simple enough so people like me can build on a foundation. I have seen some of Sam’s videos on YouTube and they are a good start but they are still assuming people have an understanding of writing a script. I have also been trying to find detailed info on snippets with examples and clear explanations on what each one does.I know this is sounding like a whinge but I am loving this app and want to get the most out of it. Interested in your thoughts. I hope this is taken in a positive way as it is not intended otherwise.
I am using the trial version of Tap Form. I wrote this first simple script but it doesn’t work. Could you tell me the error please :
function Phonedemarcheur() {
record.getFieldValue(Dem);
if (document.form.Dem.value = “Yvon Lainé”){
document.form.phoneDem.value = “06 xx xx xx xx” ;
}
}
You are most likely right. Unfortunately, I am completely inexperienced when it comes to such things in the background.
Maybe I am wrong. But in my opinion it would make more sense to enable the transfer of data from Tap Forms to a standard software / document such as MS Word / docx file (even without Java script as a native function and perhaps with the option of an existing Word document to update). Then one would not have to deal with the problems mentioned by Sam and the user would have the many possibilities of standard software (e.g. editing texts in MS Word).
It would be very helpful if you could provide the video so that I can test your suggestion here.
I think we’re getting off the topic a bit ;-) …
My only problem is that long texts cannot simply be printed (or saved as PDF). If there are multiple pages I have to work with different fields and layouts.
It would be ideal if a note field could be spanned over several pages (optionally with page numbers) as a PDF / Print.
It is also possible – this is the subject of this thread – to include the field information (address, case number, other information, …) from Tap Forms to a Word document (via Java Script). The Word document could then simply be added to the record in Tap Forms as an attachment.
…
Unfortunately, that is a very difficult topic …
Thanks.
Chris
In the script editor where it has the field list, use the ID field to get the ID’s of each of the fields you want to copy across. It’ll generate a bunch of lines with fld-something that you can use with the copyField method.
Slight refactor to Daniel’s script to create a function for copying the value across as a single line to make it easier to copy multiple fields:
function copyField(fieldId, sourceRecord, destinationRecord) {
destinationRecord.setFieldValue(fieldId, sourceRecord.getFieldValue(fieldId));
}
function New_Lesson() {
let newRecord = form.addNewRecord();
copyField('fld-531d3cf087fc4b63967e29b71d30ba53', record, newRecord);
copyField('fld-a53801440fd543669e92f0fdf955fc85', record, newRecord);
copyField('fld-4f95fc5da7eb4f6d891e66f2ee620ace', record, newRecord);
form.saveAllChanges();
// Return id of new record
return newRecord.getUrl();
}
Utils.openUrl(New_Lesson());
Attaching a sample archive as well that might help as well.
Attachments:
You must be
logged in to view attached files.
Thank You!
How do I learn to create such scripts?
You could remove the unwanted data by hand or using a script.
Thanks, Sam, for the getUrl pointer!
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks
Hi Brandon, It is always the same fields that I want to keep. So removing the other data is ok. But how do I do this? With a script?
You could use ‘duplicate record’, but this would copy all fields.
Or you can do this with a script:
function New_Lesson() {
// Get current lesson
let lesson_id = 'fld-7131629dfa4147d79ed24f05dfc83515';
let lesson = record.getFieldValue(lesson_id);
// Create new record
let newRecord = form.addNewRecord();
// Copy previous record entry
newRecord.setFieldValue(lesson_id, lesson);
form.saveAllChanges();
// Return id of new record
return newRecord.getId();
}
var id = New_Lesson();
// Jump to new record
Utils.openUrl("tapformz://record/view/"+document.getId()+"/"+form.getId()+"/"+id);
Just set the lesson_id according to your form. TapForm doesn’t display the new record when it is created from a script. To do this, I use call TapForm from TapForm with the new record Id. This is done with the last statement. You can remove it if you don’t like this behavior.
Have fun!
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks
If the new record is a child record, then you can use a calculation field to set the email address in the child record to the one of the parent record. This way, you won’t have to copy&paste it.
Otherwise, you could use a script to handle this.
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks
Thanks for your suggestion. Still does not work. Where can i find the documentation?
I took “date_time” from https://www.tapforms.com/help-mac/5.3/en/topic/javascript-api
Attachments:
You must be
logged in to view attached files.