Setting up Addresses with Variables

Viewing 9 reply threads
  • Author
    Posts
  • May 15, 2021 at 9:17 AM #44403

    Kimberley Hoffman
    Participant

    Hi Brendan and the Tap Forms community,

    I want to set up a mailing address with variables. If you look at the attachment, you will see that this will produce the following type of result

    Frau Anne Schmidt
    666 Mockingbird Lane
    38000 Munsterland
    Germany

    That is ok, but I would like to be able to exclude the honorific if it isn’t available, so that no empty space appears before the first name.

    I would also like to exclude the country if it is “Deutschland” (Germany) because I only need the country if it is not Germany. You don’t generally write the country on the label if it is the country you are in.

    How do I do those two things?

    Thanks for your help.

    Regards,
    Kimberley

    Attachments:
    You must be logged in to view attached files.
    May 15, 2021 at 3:54 PM #44406

    Sam Moffatt
    Participant

    The calculation documentation has an example of how you can omit certain items if they’re not set. Starting with that example there as a basis with some modifications (square brackets to denote field placeholders):

    IFNOTEMPTY([Anrede]; CONCAT([Anrede]; " "); "") + [VORNAME] + " " + [Name] + "\r" +
    [STRASSE_HAUSNUMMER] + "\r" +
    [PLZ] + " " + [STADT] + 
    IFEQUAL([LAND]; "Deutschland"; ""; CONCAT("\r"; [LAND]))
    

    Something like this should work, the IFNOTEMPTY is checking if the Anrede field is not empty and if so it adds it plus concats a space on the end of it otherwise it puts in an empty string so there isn’t the whitespace. The IFEQUAL at the end should test for if the country name matches and if it does match then we return an empty string otherwise we put in the new line and the country name. I use CONCAT but the + syntax should work as well.

    This is the edge of what I’d put in a calculation field because they’re hard to debug once they start to get a little more complicated. Script fields are a little better at giving you at least an error when you mess stuff up. In terms of being flexible in the address generation, I’ve got a video on using a script field to generate addresses that focused mostly on using a linked form field but the same approach would work for formatting an address.

    May 16, 2021 at 12:14 AM #44408

    Kimberley Hoffman
    Participant

    Hi Sam,
    Thank you for your help. Your video also helped me with something I haven’t yet had time to fix: my acquisition, client and projects forms.

    Back to the address label:
    The German language is a little complicated. If the addressee is male, his honorific would be “Herr”. But if you write the address for a label, the word “Herr” is no longer the grammatical subject but appears in the grammatical accusative form “Herrn”.

    Unfortunately I am not versed in scripting. I just looked up scripting 101 on the web and am already overwhelmed. I think I should be looking for Javascript return values definitions.

    I’m guessing that I would have to insert part of the script like this?

    let myText = ‘Herr’;
    let newString = myText.replace (‘Herr’, ‘Herrn’);
    console.log(newString); //

    It is definitely worth learning some basics to get more out of the Tap Forms. For this book project I will use your solution and then for my fixing my project and client files, I’ll try to follow what you showed in your video, as I can always change that on my participant list I am working on now. Maybe you have a link to even more basic scripting? Thanks.
    Regards,
    Kimberley

    May 16, 2021 at 12:51 PM #44415

    Brendan
    Keymaster

    Hi Kimberly,

    TL Ford, one of my Tap Forms customers has created a series of tutorials on Tap Forms Scripting 101 that may help you to better learn how to do scripting within Tap Forms. Some of those other JavaScript tutorials are more geared towards integrating JavaScript into web pages.

    http://cattail.nu/tap_forms/tap_forms_scripting_101/index.html

    As for the switch between Herr and Herrn, if you have some way to identify a male contact from a female contact, other than having that title, then you could use an if/then statement in JavaScript. But if you have a field in your form that already contains the values Herr or Herrn depending on the gender, then you could just insert that into your script (or Calculation field as in Sam’s solution).

    Thanks,

    Brendan

    May 16, 2021 at 5:43 PM #44418

    Sam Moffatt
    Participant

    I have a simple intro to scripting video and a script field deep dive video that might help as well. Scripting is weaved into a bunch of the videos to solve various problems, perhaps overused at times but pretty powerful.

    If the gender is important, I’d make it a field and then you can do an IF comparison in either the calculation field or the script:

    IFEQUAL([Gender];"Male"; "Herrn"; "Fraun")
    

    You could make it a checkmark field though I think a radio pick list makes a little more sense.

    Javascript makes that a little clearer:

    var title = "";
    var gender_id = "fld-1234";
    switch(record.getFieldValue(gender_id)) {
      case "Male":
        title = "Herrn";
        break;
      case "Female":
        title = "Fraun";
        break;
      default:
        title = "";
        break;
    }

    You could also make the title a pick list of a set of valid titles and then something like this perhaps could work:

    var title = "";
    var title_id = "fld-1234";
    switch(record.getFieldValue(title_id)) {
      case "Herr":
        title = "Herrn";
        break;
      case "Frau":
        title = "Fraun";
        break;
      default:
        title = record.getFieldValue(title_id);
        break;
    }

    It’s a little longer than a replace statement but it’s perhaps a little clearer.

    May 17, 2021 at 1:09 AM #44421

    Kimberley Hoffman
    Participant

    Hi Brendan and Sam
    Thanks for the tips and links.

    In German only the male honorific changes in the accusative: Herr > Herrn, Frau > Frau, Fräulein (seldomly used anymore except for girls under 16) stays Fräulein. Only adults were allowed to sign up or sign up for their kids’ sake, so I just left Fräulein out of the equation. Germans don’t seem to have an equivalent of the English neutral honorific Mx, yet. But that is another story for another day.

    I also have “Familie” meaning “Family” (like Familie Schmidt, Straße 7, PLZ Stadt). But that doesn’t change in the accusative. Yes. German is fun but also nit-picky complicated.

    The only way of identifying gender in my file is through ticking “Herr” or “Frau”. I can see where Sam’s solution is going to.

    Regards,
    Kimberley

    May 18, 2021 at 12:43 AM #44430

    Sam Moffatt
    Participant

    Ah thanks for the information. It was a bit of a stab in the dark for the sake of the example so good to know the distinction and great to see you’ve got an idea for how to solve your problem out of it :)

    May 18, 2021 at 12:53 PM #44433

    Kimberley Hoffman
    Participant

    ohhhhhhhh
    I just discovered another feature of Tap Forms I didn’t know about: I didn’t know that when you have sorting lists, you also have the ability to see the sum total of different elements in that list.

    The Program never fails to impress me. Now I don’t have to go through the finger-counting of how many, I just need to look at the bottom!

    (Thought I would add this in here. This is so grand. It makes the task of drawing 400 people so do-able)

    ?‍?????

    Attachments:
    You must be logged in to view attached files.
    May 18, 2021 at 7:09 PM #44440

    Brendan
    Keymaster

    If you enable the Show Group Summaries option you can see subtotals per section too.

    May 18, 2021 at 10:59 PM #44441

    Kimberley Hoffman
    Participant

    sigh. This is so wonderful :)

Viewing 9 reply threads

You must be logged in to reply to this topic.