Search Results for 'script'
-
Search Results
-
I’m using TapForms as a simple CRM tool and once in a while, I need to send emails using content from a record. Using a field with the type ’email’ opens the mailtool, but doesn’t provide a way to add a subject or message content.
But I found that I can trick Tapforms into launching the email tool using a “mailto:” web link! And with “mailto:” I can set the email subject and body as well.
So in my form, I have a field called “Send Email” of the type ‘Web Site’. Using a script, I set this field with a mailto link and additional content derived from my customer record. The mailto link then looks like “mailto:email@company.com?subject=…@body=…”.
Then I have a script field called ‘Create Email’ which contains following code:
// Create Email URL String function createEmailURL( recipient, subject, message) { var subject_field = subject ? "subject=" + subject : "set subject"; var message_field = message ? "&body=" + message: ""; var url = "mailto:" + recipient + "?" + subject_field + message_field; return url; } function Script() { var send_email_id = 'fld-c3fbfda318c5412fb5be8ecf2e0e7e3a'; var name = record.getFieldValue('fld-00336938a7d340a58d47a7231fe497dd'); var email = record.getFieldValue('fld-09e0ebeccf814d4b920e4021cf824997'); var message = "Dear " + name; message += "\n\nThis is my message for you!"; message += "\n\nRegards - Daniel"; var url = createEmailURL(email, "Member update", message); record.setFieldValue(send_email_id, url); document.saveAllChanges(); return url; } Script();Whenever I update a field used in my script, the Send Email field is updated. Perfect! Unfortunately, I have to do a cmd-R (Refresh Selected Record) to have the GUI reflect the update as well. It would be so good to have a Record.Refresh() function to do this from a script (Brendan, are you listening? :)!
Once done, clicking on the Web Site link, the mailtool is opened with the prepared email.
This is not efficient if one needs to send hundreds of emails, but it is perfect for one or just a few.
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksI need to send emails to members. I have a form which contains various pieces of text I routinely send mostly when there is no phone number associated with a members information.
I’d like to include fields from the record in the email like…
Dear [firstName]
Your address is [city] [state] [zip]
Well, you get the idea.
Is there a way to do this in tapforms? Perhaps thru a calculation field or a script?
Thanks,
Over on the main forum is a topic about move records from one form to another which I was curious about being able to solve.
This gives the user a list of forms excluding the currently selected one, checks to see if at least each of the fields in the source record are available in the destination and then creates a new record. In my limited testing it seems to work properly though by design it only copies records, it doesn’t delete the original so you need to do that after verification (trust, but verify).
I went through and put some comments in it that will hopefully make sense. There are two functions: the
copyHandleris a callback that does the heavy lifting and theCopy_Record_To_Formfunction sets up the initial form list and prompter.// Handler for prompter callback var copyHandler = function() { // Validate that we got a form name passed in. if (typeof formName == 'undefined' || formName.trim() == '') { console.log('Empty or undefined formName sent, cancelling.'); return; } // Mapping of source field to target field // - the key will be source field and the value will be target field. var fieldMap = {}; // List of fields in the source form that weren't found in the target form. var missingFields = []; // We shouldn't be here but let's check again. if (form.name == formName) { Utils.alertWithMessage('Unable to copy record to self', 'Please use the duplicate button to create a new record in the same form'); return; } // Get the target form. var target = document.getFormNamed(formName); // Get the source fields. var sourceFields = form.getFields(); // Iterate through each of them. for (sourceId in sourceFields) { // Look for a target field with the same name as the source field. var targetField = target.getFieldNamed(sourceFields[sourceId].name); if (targetField == null) { // If a targetField is missing, add the source field to the missing field list. missingFields.push(sourceFields[sourceId].name); } else { // Map the source field ID to the target field ID. fieldMap[sourceFields[sourceId].getID()] = targetField.getID(); } } // If we had any missing fields. if (missingFields.length) { // Prompt a message with the missing fields and let the user know it's aborted. var fullMessage = ["The following fields weren't found in the target form:", "", ...missingFields]; Utils.alertWithMessage('Copy Aborted!', fullMessage.join("\n")); return; } // Create the record data object and start to iterate through the field map. var recordData = {}; for (sourceFieldId in fieldMap) { // Set in the record data the field ID of the target field as the key // and then get the current value of the source field. recordData[fieldMap[sourceFieldId]] = record.getFieldValue(sourceFieldId); } // Don't know if this works, set a secret value to the original record URL for linking. recordData['copy-source'] = record.getUrl(); // Add a new record to the target form. var targetRecord = target.addNewRecord(); // Set the field values for the newly created record. targetRecord.setFieldValues(recordData); // Save the data and log some values for reference. document.saveAllChanges(); console.log('Original URL: ' + record.getUrl()); console.log('Destination URL: ' + targetRecord.getUrl()); } function Copy_Record_To_Form() { // Get all of the forms. var forms = document.getForms(); // A place to store a list of form names for the prompter. var formNames = []; // Iterate through all of the forms. for(var formId in forms) { // Ignore the currently selected form from the list. if (forms[formId].name == form.name) { continue; } // Append this form name to the list of form names for the prompter. formNames.push(forms[formId].name); } // Create a new prompter anddisplay the form list. var formPrompter = Prompter.new(); formPrompter.cancelButtonTitle = 'Cancel'; formPrompter.continueButtonTitle = 'Copy record'; formPrompter.addParameter('Destination Form: ', 'formName', 'popup', formNames) .show('Select form to copy record: ', copyHandler); } Copy_Record_To_Form();