How to get the right Postal Code

0
When someone adds a address they give the Dutch postal code as f.e. 2931AJ (without a space, because it calls a Postcode housenumber API, and spaces are not allowed). When saving the object I have a Change item for the postcode to add the space. (The space is needed for an excel export later on) This works fine. Later on you can do an excel export. I noticed that each time you run the export, an extra space is added tot the postal code. So in the excel sheet you get 2931    AJ. (I didn't have a change item in the microflow that creates the list for the export). Now I made a change item in the loop I don't know what I miss at line 4 Missing EOF at 'if' . The else statement is a workaround, because of the Postal code is 6 7 digits, I want it to be like it is. But you need an else statement, that's why I did the else statement like that. I just want to make sure the postal code to look in the excel export like 2931 AJ with one space.  Who can help me out?   If I do as Jelle suggested I get:
asked
2 answers
2

You do not have to add the last ' = IteratorKlant/KlantAdresPostcode ' it will work without 

and you need to if else then condition.

 

if lenght() ... > 7 

then replace()...

else if length < 7

then substring() + '' + substring()...

else $iteratorklant/KlantAdresPostcode

 

 if [condition] then [value] else [value]  

answered
1

My main suggestion would be to never save values based upon what some sort of export or external application might consume; always store it how you would like it and transform the value based on the need of the other application or export. This will also increase consistency when you have multiple places where you might store the postalcodes (so you won't have a table with postalcodes with a space and another table with postalcodes without the space). Another suggestion is to limit the amount of characters... if your max string length is 6, it should be set to 6. That way it will simply give an error when it gets larger (unexpected) than 6. Then it's easy to fix it and make sure the postalcode is saved properly at that point.

If you'd always save it without the space (easy to remove on save/change), you'd only need to add the space when exporting to excel:

substring($Postcode,0,4)+' '+substring($Postcode,4)

(assuming you already checked that the postalcode is valid and contains 6 characters).

I don't really get how exporting would add extra spaces; only thing I can think of is that with every save, a space is added (so if I save 1234AB, I get 1234 AB... and if I change it again, another space is added: 1234  AB, etc. So adding a space without checking beforehand if the space is not already present, could create unexpected results. Another strong point to set the maximum string length to your required result (6/7).

But the changes Jelle suggest would work:

image.png

answered