Jump to content

Formatting an XDF Address


AngelBenitez

Recommended Posts

Hello,

I am trying to write an XDF rule to do the following:

I have a list of people that work at different addresses. Each user's address is based on a number. The location is its own field on an Excel Spreadsheet. For example:

 

Jerry works at Location 1

Jane works at Location 2

John works at Location 3

 

I would like it if a user chooses location 1, location 2, or location 3 then it returns the complete address. The addresses are on their own individual field.

 

Location 1 = 387 Maple Street, Suite 200, Willowdale, CA 90210

Location 2 = 512 Elm Avenue, Meadowville, NY 12345

Location 3 = 241 Pine Lane, Brookside, TX 67890

 

Since the entire address is on its own individual field, I would like there to a hard return in the rule to remove the comma after the street and the second line to start with the city. Important thing to note is that some of the addresses have a suite number that I would like to stay on the first line if they have one. The addresses would like the following:

 

387 Maple Street, Suite 200

Willowdale, CA 90210

 

512 Elm Avenue

Meadowville, NY 12345

241 Pine Lane

Brookside, TX 67890

Link to comment
Share on other sites

This isn't really a question about XDFs specifically, it's just about how to split up a single-field address into multiple lines.

The good news is that, for questions like this, you can just Google something like "split address in JavaScript" and see lots of examples.

The bad news is that there's no perfect solution. It's a "how to unmake the soup" question.  Obviously it's better to have the city, state, street, etc. in their own discrete data fields, then you can combine them as needed.  Once they're joined, there's no completely reliable way to split them up.  (It's similar to the problems with un-capitalizing proper names.)

That said, depending on how consistent the formatting is in the data, something like this should work:

function splitAddressLines(address)
{
    var result = address.split(/,\s*/);
    result = result.slice(0, -2).concat(result.slice(-2).join(", "));
    return result.join("\n");
}

return splitAddressLines("87 Maple Street, Suite 300, Willowdale, CA 90210"); // or a data field, XDF field, etc.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...