Validate if address information includes House number

Post Reply
Moosi
Newbie
Posts: 5
Joined: Mon Jan 09, 2017 10:47 pm

Validate if address information includes House number

Post by Moosi »

Hello!

We process a XML with job information generated from our web shop in Enfocus Switch.
This file also contains info about the shipping address.
The XML normally looks like this:

Code: Select all

<Lieferadresse>
  <Firma />
  <Abteilung />
  <Name>Max Mustermann</Name>
  <Strasse>Musterstraße 13</Strasse>
  <PLZ>12345</PLZ>
  <Ort>Musterstadt</Ort>
  <Land>Deutschland</Land>
  <Tel>+49 1234 5678 9</Tel>
  <Email>max.mustermann@gmail.com</Email>
</Lieferadresse>
It happens from time to time that the customers do not enter a house number, so the line <Strasse> does not contain a number.
In Switch, I now want to route XML files that do not contain any number in <Strasse> to a different path in our flow.

My approach was to set a condition on the route that validates if the value <Strasse> contains a number or not.
I set a path to the value and used a regular expression to only search for numbers (\d+), type of Metadata is Text.
My idea was to validate if the result from that equals an "empty" value then go path A, if there is a value, then go path B.

But unfortunately, I can't leave the field on the right empty.
Any ideas how to resolve my problem?
Image

We do not have the Scripting Module.
User avatar
magnussandstrom
Advanced member
Posts: 510
Joined: Thu Jul 30, 2020 6:34 pm
Location: Sweden
Contact:

Re: Validate if address information includes House number

Post by magnussandstrom »

Try to set the condition to: [Switch.Calculation:Expression="[Metadata.Text:Dataset="Xml",Model="XML",Path="//Strasse",Search="\d+"]"] Greater than 0

Because if you place any numbers inside Switch Calculation you can compare with numbers instead of text.
freddyp
Advanced member
Posts: 1129
Joined: Thu Feb 09, 2012 3:53 pm

Re: Validate if address information includes House number

Post by freddyp »

The regular expression .+ means "one or more characters", so an alternative is (well, depending on how you approach it, there are 2):
variable Matches .+ for the condition that there is at least 1 character, in this case the good ones
variable Does not match .+ for the condition that there are no characters, in this case the bad ones
Moosi
Newbie
Posts: 5
Joined: Mon Jan 09, 2017 10:47 pm

Re: Validate if address information includes House number

Post by Moosi »

magnussandstrom wrote: Thu Jan 12, 2023 10:27 pm Try to set the condition to: [Switch.Calculation:Expression="[Metadata.Text:Dataset="Xml",Model="XML",Path="//Strasse",Search="\d+"]"] Greater than 0

Because if you place any numbers inside Switch Calculation you can compare with numbers instead of text.
Thank you, that worked like a charm!
I think I have used that a few years ago for something similar, but I did not remember it this time. 8-)
Post Reply