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

Creating a Control Number by concatenating fields

Guest
May 03, 2017 May 03, 2017

Can someone help me with a JavaScript question?  I'd like to create a new field which I'll call Control Number.  This field would be comprised of the first four letters in "Last Name" combined with the current date to create what would amount to a 10 digit field (NNNNDDDDDD).  This is a low volume form, so I'm not concerned about the potential for a duplicate control number.  It is essentially for reference purposes.

TOPICS
Acrobat SDK and JavaScript , Windows
379
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

correct answers 1 Correct answer

LEGEND , May 03, 2017 May 03, 2017

Here is a custom Validate script you can use in the Last Name field. It uses the characters from the last name field and converts them to upper case and uses a date format of yyyymmdd. You can change this to suit. The name of the control number field is assumed to be "Control Number", so change that if you're using a different field name.

// Custom Validate script for Last Name field

(function () {

    // Get a reference to the control number field

    var fCN = getField("Control Number");

    // If

...
Translate
LEGEND ,
May 03, 2017 May 03, 2017

What should happen if the last name field is blank or has fewer than four characters?

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
Guest
May 03, 2017 May 03, 2017

My inclination would be to follow the path of least resistance.  Ideally, the name portion of the field would be filled with asterisks or some other special character.  Spaces would be OK if that makes it easier, but I would prefer to have a visible character that could be recorded on another document.

Basically, this is going to be an order form for a certificate of deposit that could be renewed multiple times.  The control number will be manually entered into a descriptive field associated with the CD and carried with it through the renewal process so we can tie it back to the original order form.  For a variety of reasons, CD numbers change when a CD is renewed or reissued, so we can't link the order form to the first CD number. 

I hope this helps, and I thank you for taking interest in a JavaScript question from a novice.

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
LEGEND ,
May 03, 2017 May 03, 2017

Here is a custom Validate script you can use in the Last Name field. It uses the characters from the last name field and converts them to upper case and uses a date format of yyyymmdd. You can change this to suit. The name of the control number field is assumed to be "Control Number", so change that if you're using a different field name.

// Custom Validate script for Last Name field

(function () {

    // Get a reference to the control number field

    var fCN = getField("Control Number");

    // If this field is blank, blank the Control Number field

    if (!event.value) {

        fCN.value = "";

        return;

    }

    // Determine the prefix for the CN field

    var sPrefix = (event.value + "***").substr(0, 4).toUpperCase();

    // Determine the date string

    var sDate = util.printd("yyyymmdd", new Date());

    // Set the Control Number field value

    fCN.value = sPrefix + sDate;

})();

This script will be triggered whenever the Last Name field value is changed. If you want it to happen at some other time, post again with more info.

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
Guest
May 03, 2017 May 03, 2017
LATEST

Amazing!  Thank you for such an elegant solution.  It worked perfectly!

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