Tap Forms – Organizer Database App for Mac, iPhone, and iPad › Forums › Script Talk › Just a little help.
- This topic has 1 reply, 2 voices, and was last updated 3 years, 7 months ago by Sam Moffatt.
-
AuthorPosts
-
May 17, 2021 at 7:21 AM #44425
Andrew DrapperParticipantA few weeks ago you all helped me come up with this great little script that lets me send an email through TextMagic and my customer receive it as a text message. It has been working FANTASTCLY… However, If I just add to it a little bit… I will know who I have texted when they reply.
I need to edit the code so that rather than just an email address as
“phone_number@textmagic.com”
we go one step further and have
“full_name field <phone_number@textmagic.com>”
Existing code.
function SMS() { var mobilephone = record.getFieldValue('fld-314b7a6810eb44828ab4cd717f987b7e').replace(/[^0-9]/g, ''); var SMS = mobilephone + "@textmagic.com"; //console.log(SMS); const email_id = 'fld-d52d76de4eed468f9119a49b50a47f0d'; record.setFieldValue(email_id, SMS); document.saveAllChanges(); return SMS; } SMS();
Many thanks
May 17, 2021 at 9:28 PM #44427
Sam MoffattParticipantI did a quick test with a website field and this sort of syntax worked:
mailto:"Test User" <test@example.com>
I couldn’t get the email field to do what I expected it to do but this opened up Apple Mail for me and had the details prefilled. It’s almost certainly non-standard.
For your example:
function SMS() { var mobilephone = record.getFieldValue('fld-314b7a6810eb44828ab4cd717f987b7e').replace(/[^0-9]/g, ''); var name = record.getFieldValue('fld-123456'); // replace this var SMS = `mailto:"${name}" <${mobilephone}@textmagic.com>?subject=Hello, World&body=Hello ${name}`; //console.log(SMS); const email_id = 'fld-d52d76de4eed468f9119a49b50a47f0d'; record.setFieldValue(email_id, SMS); document.saveAllChanges(); return SMS; } SMS();
It’s a little more but seemed to work for me with Apple Mail. Javascript uses the backticks to denote “template strings” which means we can use variables a little more naturally than messing with plus signs. I also added an example of setting a subject and a body, no idea if that’s useful to your use case (if not, just remove them but perhaps worth a try). There are some limits on what you put in the field to ensure it makes it to Mail but give that a spin and see how you go.
You’ll have to change the field type over from email to website but otherwise you should get a similar experience.
-
AuthorPosts
You must be logged in to reply to this topic.