0

How to add field date ?

Hi,

I'm looking to add a field date & hour when I send an Email.

This is my code :

let thisList := this.'2. Candidats';
let subject := 'Email Templates'.Objet;
let body := 'Email Templates'.'Corps du mail';
let thisBody := body;
thisBody := replace(thisBody, "{Prénom}", '2. Candidats'.'Prénom');
thisBody := replace(thisBody, "{Entretien}", '2. Candidats'.Entretien);
sendEmail({
from: "MyMail",
to: '2. Candidats'.'E-mail',
subject: subject,
text: " ",
html: thisBody
})

{Prénom} is working but I've got an error on this line : thisBody := replace(thisBody, "{Entretien}", '2. Candidats'.Entretien);

*function is undefined: replace(string,string,timestamp) to the line 6, column 71*

 

You can fin my mail template here :

<b>Bonjour {Prénom}</b>
<br><br>
Suite à notre conversation téléphonique de ce jour, je vous confirme que votre entretien aura lieu le <strong><u><b>{Entretien}</b></u></strong>

I'm stuck since 2 days and I don't find this problem on forum.

Thank's you,

Sincerely

8 replies

null
    • Database Consultant
    • Kirkness_Associates_Ju
    • 5 yrs ago
    • Reported - view

    Hi Quentin

    I recognise that code!!

    The reason is that the date /time field needs to be converted to text before it can be used in the replace - you should change the line like this:

     

    thisBody := replace(thisBody, "{A Date}", format(now(), "DD.MM.YYYY, hh:mm"));

    Replacing now() with your field - and you can adjust the format to suit your needs.

    Hope this helps!

    • Boris
    • 5 yrs ago
    • Reported - view

    Hi Julian,

    Yes, it's not my code... Haha :)

    Thank you very much, it's perfect. Really, thank you !

    I've an other question. Is it possible to make it with a button ? I mean inside my HTML code. Cuz I'm looking to send differents mails without changing the code. Or maybe should'I code all function in the same button to call differents mails ?

    Once again, thank you Juilan.

     

    Have a nice day !

    • Database Consultant
    • Kirkness_Associates_Ju
    • 5 yrs ago
    • Reported - view

    I thought I'd already responded!??!

    Anyway, I'm not sure what you mean by 'Is it possible to make it with a button' - it may be answered in my blog post 'Sending Bulk Emails in Ninox':

     

    http://software.kirknessassociates.com/blog_files/458b2ac56fab5fd7375f64b354486f37-38.html

    • Boris
    • 5 yrs ago
    • Reported - view

    Hi Julian,

     

    Thank you, sorry for bad english...  I mean, is that possible to make one button per mail without using email template & mailouts.

    I'm looking to use 1 button/function and using my code inside. I'll use your function for bulk Emails but my team has to send mails per validation. If it's not possible I'll developp all "replace(" in the same button.

     

    Thank you Julian !!

    • Database Consultant
    • Kirkness_Associates_Ju
    • 5 yrs ago
    • Reported - view

    I think I see what you mean...

    You could have a button on, say, a contacts record which would send them an individual email and you could build up the text in the code:

    sendEmail({
    from: "julian@kirkness.com",
    to: recipient.Email,
    subject: "This is a test email",
    text: " ",
    html: "<h2>Test Email: " + recipient.Name + "</h2><br><br>" + 'Some more text here'
    });

    Of course, you could also still use the template idea but have a template which is either selected by the code or which you select from a dropdown list.

    • Boris
    • 5 yrs ago
    • Reported - view

    Thank you Julian for your help, I appreciate. Really!

    I'm trying to code your function "Sending Bulk Emails" using one button, without using any list (Email Templates). So, when I want to press the button "Confirmation" in the table I'm looking to send a personalized Email from field's table.

    I'll have 2 trainee in my team soon and I want to developp some mail button to avoid any problems.

    You can read my test below :

    let body := 'Prénom';
    let thisBody := body;
    thisBody := replace(thisBody, "{'2.Candidats'.Prénom}", 'Prénom');
    thisBody := replace(thisBody, "{'2. Candidats'.Entretien}", format(now(), "DD.MM.YYYY, hh:mm"));
    sendEmail({
    from: "quentin@quentin.com",
    to: 'E-mail',
    subject: "Confirmation !",
    text: " ",
    html: "Bonjour
    <a>{Prénom}.</a><br><br> Suite à blablabla le <strong><u><a>{'2.
    Candidats'.Entretien}</a></u></strong>

    })

    My main problem is : field won't be replaced so I've got a mail like this :

    Bonjour {Prénom}.

    Suite à blablabla le {'2. Candidats'.Entretien}

    It's probably because I'm a noob. That's why I appreciate your help haha !

    Your's Sincerely,

    Quentin

    • Database Consultant
    • Kirkness_Associates_Ju
    • 5 yrs ago
    • Reported - view

    Hi Quentin

    For this one off email you don't need to use replace (that is only necessary to replace 'place holders' in the templates). So you would only need something like:

    sendEmail({
        from: userEmail(),
        to: Email,
        subject: "Confirmation !",
        text: " ",
        html: "Bonjour " + Name + "<br><br> Suite à blablabla le <strong><u>" + format(now(), "DD.MM.YYYY, hh:mm") + "</u></strong>"
    })

     

    Not quite sure why you had the <a> and </a> tags in there - these are used to turn somthing into a hyperlink - and don't do anything here as they are incomplete - see:

     

    https://www.w3schools.com/tags/tag_a.asp

     

    Julian

    • Boris
    • 5 yrs ago
    • Reported - view

    Julian,

    That was so easy... Thank you once again !!

    It's just perfect right now !

    Have a nice day Julian !

Content aside

  • 5 yrs agoLast active
  • 8Replies
  • 2640Views