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);
}
Much appreciated and thank you in advance!
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 = "";
...
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 = "";
}
Copy link to clipboard
Copied
This works perfectly - thank you!