Question

I want to add a second Address field into this custom function (ie. Apt. #101). If you wanted, you could explain how the Case(not IsEmpty works and I would be willing to attempt to add the second address field in myself...

Let(
[
    x1 = Name;
    x2 = x1 & Case(not IsEmpty(Address); Case(not IsEmpty(x1); "¶") & Address);
    x3 = Case(not IsEmpty(City); City & ", ") & Case(not IsEmpty(State); Upper ( State ) & " ") & Zip;
    x4 = x2 & Case(not IsEmpty(x3); "¶") & x3;
    x5 = x4 & Case(not IsEmpty(Country); Case( not IsEmpty(x4); "¶") & Country)
];

    x5

)
Was it helpful?

Solution

I'd recommend doing away with the let statement, it seems to make it more confusing. The end goal is, you want to concatenate a bunch of address values together. If an address value is not empty, you want to put a line break (or a comma + space, for the city) after the element in question. Something like this:

LeftWords (
    Case (not IsEmpty(Customer::FullName) ; Customer::FullName & "¶" ) &
    Case (not IsEmpty(Address1) ; Address1 & "¶" ) &
    Case (not IsEmpty(Address2) ; Address2 & "¶" ) &
    Case (not IsEmpty(City) ; City & ", " ) &
    Case (not IsEmpty(State) ; Upper (State ) & " " ) &
    ZipCode
; 9999 )

The LeftWords function with an arg of 9999 (or some other suitably large value) removes any trailing newline or whitespace, which could happen if city, state, and zip are all empty.

OTHER TIPS

Let( [

   x1 = Customer::FullName;
   x2 = x1 & Case(not IsEmpty(Address1); Case(not IsEmpty(x1); "¶") & Address1);
   x3 = x2 & Case(not IsEmpty(Address2); Case(not IsEmpty(x2); "¶") & Address2);
   x4 = Case(not IsEmpty(City); City & ", ") & Case(not IsEmpty(State); Upper ( State ) & " ") & ZipCode;
   x5 = x3 & Case(not IsEmpty(x4); "¶") & x4 ];

x5

)

Use the List() function:

List( 
 Address Line 1;
 Address Line 2;
 Substitute( List( Sity, Upper( State ); ZIP ); "¶"; " " );
 Country ) )

The idea here is that the List() function ignores empty values, so you don't have to test whether they're empty or not. With address lines it will automatically ignore empties; with sity-state-ZIP line it will give you a valid list and all you have to do is to replace the separator.

If you're using FM Advanced, define a custom function to join a list with a given separator:

/* Join( separator; list *) */
Substitute( list; "¶"; separator )

This will make it simpler.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top