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

Custom Calculation to populate field with abbreviation

New Here ,
Oct 24, 2018 Oct 24, 2018

Copy link to clipboard

Copied

Hi Everyone,

I have a form that creates a project name based off of selected values in a series of dropdowns.

For example,

Dropdown 1 has the values Maryland, Virginia, Pennsylvania and Deleware

Dropdown 2 has the values Architecture, Engineering, Construction Management

Dropdown 3 has the values New Build, Modification, Demolition

when selected, the selections form a project name, ex. Maryland - Construction Management - New Build in read only fields.

Because of the way I wrote the validation, the values in Dropdown 2 and 3 are dependent on the selected value in Dropdown 1.

What I am trying to do is create the project name with an abbreviation of the selection from the dropdown. So when you select "Construction Management", it populates "CM" and when you select "Demolition" it populates "DEMO", etc. I am not able to adjust the export value in the Options tab since the selections are completely based off of a switch validation script I have built into the State dropdown.

I am using the below custom calculation to pull the data from the dropdowns into the project name

event.value = this.getField("Dropdown2").valueAsString;

How can I add a formula that pulls the data from the dropdown (ex. Construction Management) but outputs it as "CM"?

Thank you in advance, I am a newbie to this.

TOPICS
Acrobat SDK and JavaScript , Windows

Views

377

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
community guidelines
Community Expert ,
Oct 24, 2018 Oct 24, 2018

Copy link to clipboard

Copied

Hi,

It would be easier to change the drop down lists to output the preferred string so we don't have to change it, but if that is not possible then

You should be able to wrap your code in a simple if statement, you would need one for each possible entry.

var tempString = this.getField("DropDown2").valueAsString;

// if you have a lot of values it might be easier to use a switch statement, respond to this post if that would be useful.

if ( tempString == "Construction Management")

{

    tempString = "CM";

} else if ( tempString == "Another Value");

{

     tempString = "AV";

}

then you can use tempString wherever you where going to use the original value of the string.

Hope this helps

Malcolm

Votes

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
community guidelines
New Here ,
Oct 25, 2018 Oct 25, 2018

Copy link to clipboard

Copied

Malcolm,

I do have a lot of variables. I used a few of them in the example, but there are many more. Can you assist with a switch statement?

Thank you so much.

Votes

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
community guidelines
Community Expert ,
Nov 27, 2018 Nov 27, 2018

Copy link to clipboard

Copied

Hi,

the switch statement would look something like  (using the above examples)

switch ( tempString)

{

     case "Construction Management":

          tempString="CM";

          break;

     case "Another Value":

          tempString="AV";

          break;

     default:

          // always include this to cope if the value is not as expected.

          break;

}

Regards

Malcolm

Votes

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
community guidelines
LEGEND ,
Nov 27, 2018 Nov 27, 2018

Copy link to clipboard

Copied

LATEST

If I had to do this, I'd likely set up an object to associate the possible field values with the corresponding abbreviation. It's then a simple matter to look up the abbreviation given the value. For example:

var oDD2 = {

    "Construction Management" : "CM",

    "Demolition" : "DEMO",

    // Add more here

}

It would be best to place this in a document-level JavaScript. You can then get the abbreviation from a field value like this:

var sAbbr = oDD2[getField("Dropdown2").valueAsString] || "No Abbreviation";

That last part is in case there is no abbreviation available. You may want to modify if your dropdowns include an item that indicates nothing is selected, such as a single space or something like "-- Select --". I think this is better than a long switch statement.

Votes

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
community guidelines