Page 1 of 1

Validate if address information includes House number

Posted: Thu Jan 12, 2023 9:10 pm
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.

Re: Validate if address information includes House number

Posted: Thu Jan 12, 2023 10:27 pm
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.

Re: Validate if address information includes House number

Posted: Fri Jan 13, 2023 8:57 am
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

Re: Validate if address information includes House number

Posted: Sun Jan 15, 2023 8:02 pm
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-)