Script to send an email

Viewing 7 reply threads
  • Author
    Posts
  • February 25, 2023 at 5:13 AM #49028

    Jon Millar
    Participant

    Hi All. Loving TapForms so far,

    Is there any way to create a script that will run automatically when a record date field from a table = todays date?

    Any help gratefully revived
    Cheers
    Jon

    • This topic was modified 1 year, 1 month ago by Jon Millar.
    February 25, 2023 at 11:13 AM #49037

    Brendan
    Keymaster

    Hi Jon,

    You could try the Utils.openUrl() method.

    This would work to create the email. It’ll launch your mail program and put in the subject and body.

    function Email_User() {
    
        let subject = encodeURIComponent("Testing 123");
        let body = encodeURIComponent("This is what I want to say in the email");
        Utils.openUrl("mailto:support@tapforms.com?subject=" + subject + "&body=" + body);
    
    }
    
    Email_User();

    You would have to put the script into a Script Field on your Table field though. Then you’ll have to reference your Date field in your script, which will cause the trigger and add a check to see if the date is today before running the above code.

    February 26, 2023 at 3:22 AM #49046

    Jon Millar
    Participant

    Thanks Brendan that’s great.

    To fine tune it though, I need to get the record field details into the Message body, I imagine something like creating variables with “getFieldValue” and then putting those variables into the Email body. Is that Straight forward?

    One more thing. That script beautifully creates the email but can the script also automatically send it rather than just create it and leave it for you to manually “send” ?

    Thanks again
    Cheers
    Jon

    February 26, 2023 at 10:13 PM #49047

    Brendan
    Keymaster

    I don’t think it can send it automatically. It’s just a way to compose an email.

    And yes, you’d use the record.getFieldValue(); function to get a value from the record and embed it within the body. In the body variable I have in the sample you’ll have to concatenate the strings from the values you get from the record for your fields.

    You can’t get too complicated with the body though because it can only be plain text.

    February 27, 2023 at 12:07 AM #49048

    Jon Millar
    Participant

    Ok , understand thanks

    What about incorporating the likes of Zapier soo that it can trigger actions from TapForms ?

    Airtable has such functionality. Is that something that might be possible to incorporate?

    Cheers Jon

    February 27, 2023 at 12:39 AM #49049

    Brendan
    Keymaster

    I’m not familiar with Zapier. But if it’s a web service API, you can use Utils.postJsonToUrl() or Utils.postContentToUrlWithContentType() functions to send data to an external web service.

    February 27, 2023 at 1:17 AM #49050

    Sam Moffatt
    Participant

    I signed up to Zapier and gave it a spin, if you create a Zap using the “Webhooks by Zapier” option, you can use the URL it gives you to call into Utils.postJsonToUrl():

    
    function Test() {
    	let result = Utils.postJsonToUrl(JSON.stringify({"test":"data","values":[1,2,3]}), "https://hooks.zapier.com/hooks/catch/14644114/3olzaie/");
    	console.log(JSON.stringify(result));
    }
    
    Test();
    

    Very simple example of a test function to call into the hook URL (that was a quick one I created) and you can see what the response was. In my case it looked like this:

    
    {"status":"success","id":"018691ed-550d-fb09-043e-22f9bf52151b","attempt":"018691ed-550d-fb09-043e-22f9bf52151b","request_id":"018691ed-550d-fb09-043e-22f9bf52151b"}
    

    And in the UI it accepted the values I handed it. If you’re in that ecosystem it should work to send it structured data that you can move from there.

    • This reply was modified 1 year, 1 month ago by Sam Moffatt.
    February 28, 2023 at 12:18 PM #49061

    Jon Millar
    Participant

    Thanks Sam, I’m have ac look and try to get my head around it! Cheers 😊

Viewing 7 reply threads

You must be logged in to reply to this topic.