String formatting from textbox value - Leading zeros/spaces

Hello,
I am concatenating several strings into a barcode. Each segment is coming from a textbox value and needs to be padded (left) with either a zero or a space depending on the variable.
I have tried numerous Python functions and stringFormat based on some posts here.
I get an error no matter what I try.

This is a script action based on a form button click FYI.

Something like this would be great if it worked.

LotNumber = event.source.parent.getComponent('txtLotNumber').text
LotNumber = numberFormat(LotNumber,"0000000")

Thanks!

the str() isnt neccecary if you are sure you get in in as string
rjust/ljust works with every char (also numbers and spaces)

	LotNumber1 = str(LotNumber).zfill(7)
	LotNumber2 = str(LotNumber).rjust(7, '-') #(you can use space ' ' too instead of '-')
	LotNumber3 = str(LotNumber).ljust(7, '-') #(you can use space ' ' too instead of '-')

image
image

Thanks, worked like a charm.

1 Like