Page 1 of 1

Metadata: Add a leading zero to a single digit number

Posted: Fri Nov 10, 2023 3:01 pm
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

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

Posted: Fri Nov 10, 2023 4:36 pm
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

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

Posted: Fri Nov 10, 2023 11:10 pm
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 8972 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.

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

Posted: Tue Nov 14, 2023 1:01 pm
by nmichael
Thanks to both of you. I will try these :)