1

Creating an address block from different fields

I have a shipping table with different fields for address components (line 1-4, city, state, post code)

I can create a block showing the address without the if formulas, but if say line 3 and 4 are empty they show us line breaks, which I don't want, which is why I'm attempting this with an if then, but I feel like its not the way to go.

 

Current code:

 

let line1 := 'Shipping Address'.'Address Line 1';
let line2 := 'Shipping Address'.'Address Line 2';
let line3 := 'Shipping Address'.'Address Line 3';
let line4 := 'Shipping Address'.'Address Line 4';
let city := 'Shipping Address'.City;
let state := 'Shipping Address'.State;
let pc := 'Shipping Address'.'Post Code';
if line1 != null then
line1 + "
" and if line2 != null then
line2 + "
" and if line3 != null then
line3 + "
" and if line4 != null then
line4 + "
" and city + " " + state + "
" + pc
end
end
end
end

11 replies

null
    • Mconneen
    • 5 yrs ago
    • Reported - view

    Given.. 

    form

    Here is the code for Address Label

    theCode

    • wstarnes
    • 5 yrs ago
    • Reported - view

    Fantastic formula!  Thank you! Very userful!!

    • New_Sun
    • 5 yrs ago
    • Reported - view

    i need fonts to be Bold. is it possible?

    • New_Sun
    • 5 yrs ago
    • Reported - view

    i found bold thank you

    • SECOS Group
    • quartz_cap
    • 5 yrs ago
    • Reported - view

    I forgot to thank you back then Mconneen - works a treat, tah!

    • Mconneen
    • 5 yrs ago
    • Reported - view

    @Sarah... No worries.. that is what the forum is for.     There are also several Ninox Solution Partners that offer FREE YouTube channel (Ninox Learning) as well as pay as you go one on one training. 

    • Michael_Chung
    • 2 yrs ago
    • Reported - view

    Mconneen

     

    Thanks for this. It was exactly what I was looking for.

    One question. What is the purpose of the "t" vairiable a "this" comand?

    I tried it without and it works exactly the same.

      • Fred
      • 2 yrs ago
      • Reported - view

      Michael The "magical" this command gathers all the data from the current record. You can see in line 3 all the fields start with "t.". This tells Ninox where the data for the array is coming from.

      Instead of creating a variable for address line 1, address line 2, etc. We can just use "this" and then we can reference any field that is in the table.

      • Alain_Fontaine
      • 2 yrs ago
      • Reported - view

      Michael The fact that the script works exactly the same without introducing the variable "t" is not surprising, since in this case it is completely redundant.

    • Alain_Fontaine
    • 2 yrs ago
    • Reported - view

    And another proposed solution:

    let c := join([City, State, 'Post Code'][!= ""], " ");
    join(['Address Line 1', 'Address Line 2', 'Address Line 3', 'Address Line 4', c][!= ""], "
    ")
    
    • Michael_Chung
    • 2 yrs ago
    • Reported - view

    Thanks all for the help.

     

    I ended up with this code which formats the postal address filed depending on the country selects on the combo box "country".

    Easy to add more countrys and address formats as needed. 

    let xAdUS := (
            let s := "";
            let a := ['Address 1', 'Address 2', 'Address 3', 'Address 4'];
            let p := "";
            for i in range(0, 4) do
                p := item(a, i);
                if length(p) > 0 then
                    s := s + p + "
    "
                end
            end;
            s + City + " " + State + " " + 'Post Code' + "
    " + Country
        );
    let xAdUK := (
            let s := "";
            let a := ['Address 1', 'Address 2', 'Address 3', 'Address 4'];
            let p := "";
            for i in range(0, 4) do
                p := item(a, i);
                if length(p) > 0 then
                    s := s + p + "
    "
                end
            end;
            s + City + "
    " + 'Post Code' + "
    " + Country
        );
    let xAdFrance := (
            let s := "";
            let a := ['Address 1', 'Address 2', 'Address 3', 'Address 4'];
            let p := "";
            for i in range(0, 4) do
                p := item(a, i);
                if length(p) > 0 then
                    s := s + p + "
    "
                end
            end;
            s + 'Post Code' + " " + City + "
    " + Country
        );
    let xAdHK := (
            let s := "";
            let a := ['Address 1', 'Address 2', 'Address 3', 'Address 4'];
            let p := "";
            for i in range(0, 4) do
                p := item(a, i);
                if length(p) > 0 then
                    s := s + p + "
    "
                end
            end;
            s + City + "
    " + Country
        );
    switch text(Country) do
    case "AUSTRALIA":
        xAdUS
    case "USA":
        xAdUS
    case "UNITED KINGDOM":
        xAdUK
    case "CANADA":
        xAdUS
    case "FRANCE":
        xAdFrance
    case "GERMANY":
        xAdFrance
    case "HONG KONG":
        xAdHK
    default:
        xAdUS
    end
    

Content aside

  • 1 Likes
  • 2 yrs agoLast active
  • 11Replies
  • 2276Views
  • 4 Following