Help with grabbing a number from 1 place and adding it to another with a number behind it.

New Here ,
Aug 30, 2017

Copy link to clipboard

Copied

So, i got a button which grabs a employee number from a field and adding it to another field. I want my from to add a number behind the number it just grabbed, but so far i can only get it to add the number to current number instead of putting it behind it. Everything else i've done is wrking (Got an alert if the field the button grabs data from is empty and got it to grab the number and paste it in the field) but from here im lost. Everything i've tried just aint working. This is my current code.

var f = this.getField("Medarbejder nr").valueAsString;

var v = this.getField("Løbenummer").valueAsString;

var msg = "Udfyld medarbejder nummer først";

if (this.getField("Medarbejder nr").valueAsString=="") {

this.getField("Løbenummer").valueAsString=="" && app.alert(msg,1)}

else {

    this.getField("Løbenummer").value = util.printf(this.getField("Medarbejder nr").value +1);

}

I understand the +1 in the last line is what is wrong, but i dont know what to replace it with.

Thanks.

Edit: My boss just informed me that he only want the last 3 digits of the field "Medarbejder nr" then add 3 numbers behind it starting with 001. Help with this aswell would be greatly appriciated.

Edit2: Got the number splitted so i only get the last 3 digits of "medarbejder nr", still need help with adding the 3 digits after it starting with 001.

TOPICS
Acrobat SDK and JavaScript

Views

57

Likes

Translate

Translate

Report

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

Help with grabbing a number from 1 place and adding it to another with a number behind it.

New Here ,
Aug 30, 2017

Copy link to clipboard

Copied

So, i got a button which grabs a employee number from a field and adding it to another field. I want my from to add a number behind the number it just grabbed, but so far i can only get it to add the number to current number instead of putting it behind it. Everything else i've done is wrking (Got an alert if the field the button grabs data from is empty and got it to grab the number and paste it in the field) but from here im lost. Everything i've tried just aint working. This is my current code.

var f = this.getField("Medarbejder nr").valueAsString;

var v = this.getField("Løbenummer").valueAsString;

var msg = "Udfyld medarbejder nummer først";

if (this.getField("Medarbejder nr").valueAsString=="") {

this.getField("Løbenummer").valueAsString=="" && app.alert(msg,1)}

else {

    this.getField("Løbenummer").value = util.printf(this.getField("Medarbejder nr").value +1);

}

I understand the +1 in the last line is what is wrong, but i dont know what to replace it with.

Thanks.

Edit: My boss just informed me that he only want the last 3 digits of the field "Medarbejder nr" then add 3 numbers behind it starting with 001. Help with this aswell would be greatly appriciated.

Edit2: Got the number splitted so i only get the last 3 digits of "medarbejder nr", still need help with adding the 3 digits after it starting with 001.

TOPICS
Acrobat SDK and JavaScript

Views

58

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 30, 2017 0
Adobe Community Professional ,
Aug 30, 2017

Copy link to clipboard

Copied

There is the concatenation operator for the String object. This can be concat or "+" and be sure to use the "String" constrictor since you are dealing with numbers and you want them to be strings.https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 30, 2017 0