Metadata: Add a leading zero to a single digit number

Post Reply
nmichael
Newbie
Posts: 8
Joined: Wed Oct 28, 2015 9:37 pm

Metadata: Add a leading zero to a single digit number

Post by nmichael »

Hi,

in a given XML, I have a node that contains the number 2, but this may also be any other number up to 99.
For later usage, I need to add a leading zero to all single digit numbers. Is this possible with a Metadata expression?

I currently use [Metadata.Integer:Dataset="Xml",Model="XML",Path="/daten/kopf_und_posten_daten/positionen/position/FortlaufendeBelegPosition"] to get the number, but have not beed able to add a the 0.

Maybe someone can help or tell if this is even possible.

Thanks and have a nice weekend :)

Nico
r.zegwaard
Member
Posts: 93
Joined: Fri Jul 08, 2011 10:31 am
Location: The Netherlands

Re: Metadata: Add a leading zero to a single digit number

Post by r.zegwaard »

Hi Nico,

This works for me (on another xml):

Code: Select all

[Metadata.Text:Dataset="BatchJdf",Model="XML",Path="substring(concat('0' , //dn:GeneralID[@IDUsage='batchQuantity']/@IDValue), 4 - string-length(//dn:GeneralID[@IDUsage='batchQuantity']/@IDValue))"]
For you it would be this (not tested):

Code: Select all

[Metadata.Text:Dataset="BatchJdf",Model="XML",Path="substring(concat('0' , /daten/kopf_und_posten_daten/positionen/position/FortlaufendeBelegPosition), 4 - string-length(/daten/kopf_und_posten_daten/positionen/position/FortlaufendeBelegPosition))"]
Note that it uses a Matadata.Text instead of Metadata.Integer

Robert
User avatar
magnussandstrom
Advanced member
Posts: 365
Joined: Thu Jul 30, 2020 6:34 pm
Location: Sweden
Contact:

Re: Metadata: Add a leading zero to a single digit number

Post by magnussandstrom »

Hi Nico,

If you don't have the scripting module you could do this:

Set job Private data:

Code: Select all

FortlaufendeBelegPosition=[Metadata.Integer:Dataset="Xml",Model="XML",Path="/daten/kopf_und_posten_daten/positionen/position/FortlaufendeBelegPosition"]
Then use the app Private Data Magician to add a leading zero for 1-9:
zeros.png
zeros.png (57.79 KiB) Viewed 5768 times
Now you can use the private data field FortlaufendeBelegPosition and the single digits will have a leading zero.

Maybe not the prettiest solution but it works.
nmichael
Newbie
Posts: 8
Joined: Wed Oct 28, 2015 9:37 pm

Re: Metadata: Add a leading zero to a single digit number

Post by nmichael »

Thanks to both of you. I will try these :)
Post Reply