Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
4

Document title can't show a 0 / function fillin

Community Beginner ,
Dec 06, 2023 Dec 06, 2023

Hi All,

 

I have a document that's used for user agreements that has JavaScript in it to concatenate strings for a document title.

That works great but we've only used it for tagnames sofar, ex: XX123456.

 

Now we also want to use the same document for other tags numbers that start with 0. ex. 012345.

Problem is that the generated documenttitle never shows the 0, and i'm not an expert on this so I really don't know how to solve this.

 

Anyone here got the golden tip for me? 🙂

 

p.s. for some reason the forum says I'm using a bad word in the script so I've uploaded it in a text document.

 

 

 

TOPICS
General troubleshooting , How to , JavaScript , Modern Acrobat , PDF
985
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
2 ACCEPTED SOLUTIONS
Community Expert ,
Dec 06, 2023 Dec 06, 2023

The thing about numbers is that they don't start with 0. Only strings can start with a "0" character.  A number is just a number. So you have to be careful about how you think about number representation and how strings are built from numbers. 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 07, 2023 Dec 07, 2023

Get the value of this field with valueAsString.

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 06, 2023 Dec 06, 2023

the script 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 06, 2023 Dec 06, 2023

function fillin(s1, s2, s3, sep = "") {

/*

Purpose: concatenate up to 3 strings with an optional separator

inputs:

s1: required input string text or empty string

s2: required input string text or empty string

s3: required input string text or empty string

sep: optional separator sting

returns:

sResult concatenated string

*/

// variable to determine how to concatenate the strings

var test = 0; // all strings null

var sResult; // reslut string to return

// force any number string to a character string for input variables

s1 = s1.toString();

s2 = s2.toString();

s3 = s3.toString();

//if(sep.toString() == undefined) sep = ''; // if sep is undefined force to null

/*

assign a binary value for each string present

so the computed value of the strings will indicate which strings are present

when converted to a binary value

*/

if (s1 != "") test += 1; // string 1 present add binary value: 001

if (s2 != "") test += 2; // string 2 present add binary value: 010

if (s3 != "") test += 4; // string 3 present add binary value: 100

/* return appropriate string combination based on

calculated test value as a binary value

*/

switch (test.toString(2)) {

case "0": // no non-empty strings passed - binary 0

sResult = "";

break;

case "1": // only string 1 present - binary 1

sResult = "Bruikleen" + sep + s1;

break;

case "10": // only string 2 present - binary 10

sResult = "Bruikleen" + sep + s2;

break;

case "11": // string 1 and 2 present - binary 10 + 1

sResult = "Bruikleen" + sep + s1 + sep + s2;

break;

case "100": // only string 3 present - binary 100

sResult = "Bruikleen" + sep + s3;

break;

case "101": // string 1 and 3 - binary 100 + 001

sResult = "Bruikleen" + sep + s1 + sep + s3;

break;

case "110": // string 2 and 3 - binary 100 + 010

sResult = "Bruikleen" + sep + s2 + sep + s3;

break;

case "111": // all 3 strings - binary 100 + 010 + 001

sResult = "Bruikleen" + sep + s1 + sep + s2 + sep + s3;

break;

default: // any missed combinations

sResult = "";

break;

}

return sResult;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 06, 2023 Dec 06, 2023

How does you create the document title?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 06, 2023 Dec 06, 2023

The thing about numbers is that they don't start with 0. Only strings can start with a "0" character.  A number is just a number. So you have to be careful about how you think about number representation and how strings are built from numbers. 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 07, 2023 Dec 07, 2023

Yeah I understand.

The thing is that Dutch mobile numbers start with 0. But if it's impossible we'll have to live with it 😉

Below is what's happening now. Left is the field we fill in, right is the generated title. 

 

uu.pnguu2.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 07, 2023 Dec 07, 2023

What format does you use at the input field?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 07, 2023 Dec 07, 2023

"None" 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 07, 2023 Dec 07, 2023

Get the value of this field with valueAsString.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 08, 2023 Dec 08, 2023
LATEST

That did the job! Thank you. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines