Skip to main content
Participant
May 29, 2024
Answered

Combine multiple field entries into one field with "-" separations

  • May 29, 2024
  • 1 reply
  • 516 views

I have three specific fields in a PDF form that I would like to combine into a single field (that is then used for filenaming later on).

 

Currently I have the three field appearing as a string of numbers, but I would like a "-" (dash) between each field (so the filename is easier to decode).

 

Currently I have the following:

Run custom validation script:

event.value = event.value.replace(/\D/g, "");

 

Custom calculation script:

var s = this.getField("exchange_date").valueAsString + this.getField("part_origin").valueAsString + this.getField("kr_art_nr").valueAsString;

event.value = s.replace(/^, |, $/g, "");

 

but with this it correctly removes the '/" from between the yyyy/mm/dd to present it correctly as yyyymmdd, but I would like everything to appear as follows:

 

exchange_date-part_origin-kr_art_nr

20240529-123456-987654

 

Been battling this for a few hours and cannot seem to find the trick to make this work!

 

Much appreciate your help.

This topic has been closed for replies.
Correct answer try67

Remove the validation script and use this for the calculation:

 

var s1 = this.getField("exchange_date").valueAsString.replace(/\D/g, "");
var s2 = this.getField("part_origin").valueAsString.replace(/\D/g, "");
var s3 = this.getField("kr_art_nr").valueAsString.replace(/\D/g, "");

event.value = s1 + "-" + s2 + "-" + s3;

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
May 29, 2024

Remove the validation script and use this for the calculation:

 

var s1 = this.getField("exchange_date").valueAsString.replace(/\D/g, "");
var s2 = this.getField("part_origin").valueAsString.replace(/\D/g, "");
var s3 = this.getField("kr_art_nr").valueAsString.replace(/\D/g, "");

event.value = s1 + "-" + s2 + "-" + s3;