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

SetFieldValue function ONLY if specific box is populated.

New Here ,
Nov 10, 2022 Nov 10, 2022

Copy link to clipboard

Copied

Greetings!

 

(Using Adobe Acrobat Pro)

 

Currently I have a Location dropdown/combobox that has a list of buildings and the selection will auto-populate the Building Codes field - this works very well. However I was hoping to make it more dynamic so that it only populates that field if the correlating/adjacent Account Row field is populated.

 

For example - If I select a Location it would auto-populate Building Code if AccountRow is populated, Building Code1 if AccountRow1 is populated, but does not populate Building Code2 if AccountRow2 is unpopulated.

 

I already have the auto-population code below and will include a snip of the sheet below that to provide visual context.

 

Document Javascripts:

var AccountCodes = { Building1:{ building: "0001" }, Building2:{ building: "0002" }, "Building3":{ building: "0003" }};
function SetFieldValues(cBldng) {
this.getField("Building Code").value = AccountCodes[cBldng].building;
this.getField("Building Code1").value = AccountCodes[cBldng].building;
this.getField("Building Code2").value = AccountCodes[cBldng].building;
}

 

Location Custom Keystoke Script:
if( event.willCommit ) {
if(event.value == " ") this.resetForm(["Building Code"]); else SetFieldValues(event.value);
}

 

Bill270687883z6d_0-1668117240284.png

Much appreciated and thank you in advance!

TOPICS
JavaScript , PDF forms

Views

447

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

correct answers 1 Correct answer

Community Expert , Nov 10, 2022 Nov 10, 2022

Change the scripts around so that it is executed from a custom calculation script in the Building Code Field. 

 

For Example, here's a document level function that should be called from the BuildingCode Calculation Field. 

 

// Document Scripts
var rgRow = /(\d{1,2})$/;
function BuildingCodeCalc(){
    // First, check for valid location
    var cCode = AccountCodes[this.getField("Location").value].building;
    if(!cCode) return;

    // Next get the field name row postfix
    var cRow = "";
   
...

Votes

Translate

Translate
Community Expert ,
Nov 10, 2022 Nov 10, 2022

Copy link to clipboard

Copied

Change the scripts around so that it is executed from a custom calculation script in the Building Code Field. 

 

For Example, here's a document level function that should be called from the BuildingCode Calculation Field. 

 

// Document Scripts
var rgRow = /(\d{1,2})$/;
function BuildingCodeCalc(){
    // First, check for valid location
    var cCode = AccountCodes[this.getField("Location").value].building;
    if(!cCode) return;

    // Next get the field name row postfix
    var cRow = "";
    if(rgRow.test(event.targetName))
      cRow = RegExp.$1;

    // Get Adjacent Account field value
    var cAccnt = this.getField("AccountRow" + Row).valueAsString;
    // Set code if account is non-empty
    if(cAccnt != "")
        event.value = cCode ;
    else 
        event.value = "";
}

 

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

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 ,
Nov 18, 2022 Nov 18, 2022

Copy link to clipboard

Copied

LATEST

This works perfectly - thank you!

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