cancel
Showing results for 
Search instead for 
Did you mean: 

Add leading zero to value using script in Adobe form

uirji_netweaver
Participant
0 Kudos

My requirement is print the barcode with page number and other field values , the page number length should be 2 digits ( ex: 00,01,02..etc) , i added the below logic for page number , i see page number is printing without leading zero , so i added the below code to concatenate the leading zero , but its not working , please review the code and let me know for the correction.

var pagen = xfa.layout.page(Ref($));

var flen = string(pagen).length;

if (flen=1)

{

this.rawValue = concat("0", pagen , "01" , counter)

else

this.rawValue = concat(pagen , "01" , counter)

}

Sandra_Rossi
Active Contributor
0 Kudos

Did you debug it, what happens?

uirji_netweaver
Participant
0 Kudos

Hi Sandra,

Thanks for the reply , in debugging i see length is never filled, i tried below code also. i dont see any syntax error but the length field (flen) is never filled , so what right syntax to calaclate no of digits of number ?

var pagen = xfa.layout.page(Ref($));
var flen = pagen.length;
if (flen < 2)then
this.rawValue = concat("0", pagen , "01" , counter)
else
this.rawValue = concat(pagen , "01" , counter)
endif
Sandra_Rossi
Active Contributor

"length" would work if page is of type string. What is value and type of pagen by debugger?

"concat" is a method of the String object, you can't use like that. Concatenation is "usually always" done using + in javascript.

Are you really sure that you debug step by step till the end? What happens?

You'd better look at javascript documentation and forums.

Javascript is not a SAP language. See wikipedia.

Please provide all information we need to understand.

uirji_netweaver
Participant
0 Kudos

Thanks for the reply, value of 'pagen' is 1 ( it always provides the current page number).

in debugging mode i see error " accessor: pagen.length is unknown".

look like length function work for string only , please let me know how do i find the length/no. of digits of number?

Thanks

NK

Sandra_Rossi
Active Contributor
0 Kudos

KISS pseudo code:

if i < 10 then length = 1

else if i < 100 then length = 2

etc.

or search javascript forums how to convert number to string, you can imagine how much frequent is the question (or just read the javascript reference documentation).

Accepted Solutions (0)

Answers (0)