Copy link to clipboard
Copied
I have a form in which I keep track of my weekly trips. I have one section of 10 lines with 5 fields; trip number, line haul, fsc, permits and net. I have a second section (Permits) with 6 lines of 5 fields; trip number, state, permit number, gross, net. If I enter the cost of a permit in the gross field in the Permits section, I need it to populate the permit field in the first section with the same trip number plus $15. The challenge here is that the first entry in the permit section may need to populate any of the gross fields in the first section and there may be more than 1 permit section entry for that field. Hopefully I've explained this well enough.
Copy link to clipboard
Copied
The multiple sections and multiple lines add some some complexity to the behavior of your form. So, we're going to need a clearer explanation. What would help would be if all the sections where named. Then rather than saying first section, you'd use the section name, like you have for Fuel and Permits. Also you need to be very clear about the fields. At first you say that the Gross field is entered manually in the Permit section. These are the only fields with a colum header of "Gross". Then you say that first entry in the permit section may need to populate a "Gross" field in the first section, where there is no Gross column. I think you mean to say that a Gross field in the permit section may need to populate more than one Permit field in the first section. I'm sure this is all clear to you, but for us the complexity of this form requires exact language.
So you are implying that multiple lines in the first section may have the same trip#? Since it is the trip number that connects the lines in the different sections. Does also that mean that more than one line in the Permit section may have the same trip#? What happens when multiple Gross fields reference the same trip# and therefore the same permit fields in the first section?
Copy link to clipboard
Copied
It's a work in progress and I've made some changes. I've uploaded the current version.
The upper most section is for the general trip information. This is where I enter the trip number which will auto-populate the Trip Number in the "Revenue" section. The Revenue section is what I had previously refered to as the first section. There is only one unique trip number for each trip. There are 2 pertinent sections; Revenue and Permits. The Revenue section lists what each individual trip pays. In this section I am trying to populate the permits fields. There are 10 so lets call them Permits 1 thru 10. The information for these comes from the Costs fields in the "Permits" section. There are 6 of these fields. We'll call them Cost 1 thru 6. Unlike the Revenue section, the Permits section may contain identical Trip Numbers because there may be more than one permit for a single trip. Whichever Cost fields in the Permits section need to be calculated into the single Permits field in the Revenue section with the same Trip Number. That would be (Cost + $15) * 0.7. If there is more than one then it would be (Cost1 + $15) *0.7 + (Cost2 + $15) * 0.7, so on and so forth. I aslo need the Permits fields in the Revenue Section to be blank if there are no permits for that trip.
I hope this clears up any confusion and misunderstanding.
Copy link to clipboard
Copied
Yes it does. But it's also not a simple request.
And have you noticed that this file is huge. The reason is that the Form dictionary contains font definitions for 50 different fonts that are not used anywhere on the form. I would suggest you start over. Create the form design in Word, convert to PDF and then copy over the real fields. This will give you a clean starting PDF.
Now how much coding experience do you have, and how much do you want to learn?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Not sure how you make it work because from first glance of the script there are numerous errors, for example when comparing use two equal signs not one:
(t1= pt5)
(t1== pt5)
Also with multiple conditions you need to use like this:
(t1= pt5&& pt6)
(t1== pt5&& t1==pt6)
Copy link to clipboard
Copied
Thats kinda the long way around, but you have the right idea. In fact, even though it's brute force, I think your code is spot on for the program flow. Unfortunely this particular problem you are trying to solve has a complexity issue. If you write brute force code for every contingency in every field you will end up with a large mess that will be very difficult to debug and maintain.
Here's how I would solve the issue,
First I would name the fields so that fields that work together have similar name components, which it looks like you've done. The idea is that code on one field can instantly identify the related fields that are needed for that particular script. This generalized the code so that every field has exactly the same code. The code is then placed in a document level fuction. You then have one block of simple generalized code in one place.
Since the action for this problem is happening on the "Permit" fields in the Revenue section, and the data is coming from multiple fields, the code should be a calculation script on the Permit field. Which is what it looks like you are doing. But rather than creating a large if/then block. I'd write loop that searches for each matching trip number and adds the matches to a sum variable. the nReturn variable.
So "nReturn" should be declared and initialized once at the top of the code. No variable should ever have more than one "var" statement. Like this:
The following code assumes that all field names in the revenue section are prefixed with "Revenue"
So the trip numbers are "Revenue.TripNumber.Row1", "Revenue.TripNumber.Row2" etc.
All field names in the Permit section are prefixed with "Permit"
So the trip numbers are "Permit.TripNumber.Row1", "Permit.TripNumber.Row2" etc.
amd the cost fields would then be "Permit.Cost.Row1", "Permit.Cost.Row2" etc.
This group naming allows all fields in a group to be acquired at one time. So it doesn't matter how may rows there are. You can add new rows and no code changes are needed. Simple and efficient.
function CalculatePermitCost()
{
var nReturn = 0;
var strRow = event.targetName.split(".").pop();
var nCurTrip = Number(this.getField("Revenue.TripNumber." + strRow).valueAsString);
var aPermitTrips = this.getField("Permit.TripNumber").getArray();
for(var i=0;i<aPermitTrips;i++)
{
if(nCurTrip == aPermitTrips.value){
// Get related Cost fields and calcualte
nReturn += some calculation
}
}
event.value = nReturn;
}
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more