Copy link to clipboard
Copied
Good day,
I would like to convert an existing Excel spreadsheet (Expense Claim Sheet) containing formulas and linked data to a fillable PDF form retaining all the functionality of the formulas. I know there is no direct conversion so I have begun doing this manually with Acrobat Javascript derived from other forum posts searched here as I am not a programmer at all.
Please if someone can assist with the below issues I would greatly appreciate it or advise if the Excel document should just be used instead, as I cannot find solutions to the below with the knowledge I have; I can provide links to the original Excel file and PDF file I'm still working on if required - thanks:
var Itemlist = this.getField("Expense Account Description.0");
var Price = this.getField("Expense Account No.0");
if(event.willCommit)
{
switch(event.value){
case "Production":
Itemlist.setItems(["-Select Production Account-", "Purchases Design Consumables", "Production Consumables - Roll"]);
Price.value = "";
break;
case "Maintenance":
Itemlist.setItems(["-Select Maintenance Account-", "Tool Replacement", "R & M Ink Electrical"]);
Price.value = "";
break;
default:
Itemlist.setItems([""]);
Price.value = "";
break;
}
}
var Itemlist = this.getField("Expense Account Description.1");
var Price = this.getField("Expense Account No.1");
if(event.willCommit)
{
switch(event.value){
case "Production":
Itemlist.setItems(["-Select Production Account-", "Purchases Design Consumables", "Production Consumables - Roll"]);
Price.value = "";
break;
case "Maintenance":
Itemlist.setItems(["-Select Maintenance Account-", "Tool Replacement", "R & M Ink Electrical"]);
Price.value = "";
break;
default:
Itemlist.setItems([""]);
Price.value = "";
break;
}
}
var Itemlist = this.getField("Expense Account Description.2");
var Price = this.getField("Expense Account No.2");
if(event.willCommit)
{
switch(event.value){
case "Production":
Itemlist.setItems(["-Select Production Account-", "Purchases Design Consumables", "Production Consumables - Roll"]);
Price.value = "";
break;
case "Maintenance":
Itemlist.setItems(["-Select Maintenance Account-", "Tool Replacement", "R & M Ink Electrical"]);
Price.value = "";
break;
default:
Itemlist.setItems([""]);
Price.value = "";
break;
}
}
2. Secondly, the amounts in the "Amount Excl." and "VAT" column do not update to the correct amounts as they should when for instance the value is changed in the "Amount Incl." column and the "Yes" option was initially checked under the "VAT?" dropdown (they do however update automatically). The dropdown needs to be clicked "No" / "blank" and then clicked "Yes" for a second time for the columns to then update to the correct amounts (VAT needs to remain consistent at 15% of the “Amount Excl.”) - this is done automatically in Excel.
Can this be fixed to auto-update correctly in the code? And where?
This poses a problem if, say someone entered the incorrect amount initially and selected "Yes" for "VAT" and then wanted to change that amount before completing the form, but wasn't aware that they needed to click through the options again to ensure the correct “VAT” and “Amount Excl.” amounts were displayed and neglected to check the percentage. (see below code for "VAT?" dropdown under 'custom keystroke script' under the 'format' tab in 'properties' and screenshots below):
if(event.willCommit)
{
console.println(event.value);
switch(event.value)
{
case "Yes":
this.getField("VATRow1.0").value = this.getField("Amount InclRow1.0").value / 1.15 * 0.15;
break;
case "No":
this.getField("VATRow1.0").value = 0;
break;
default:
this.getField("VATRow1.0").value = 0;
break;
}
}
Copy link to clipboard
Copied
In dropdown fields properties under 'Options' tab check 'Commit selected value immediately', also if you have issue with delay select 'Prepare form' tool, click on 'More' then on 'Set field calculation order' and make sure fields that calculate firsts are on top.
If it would be helpful to you, you could set account number as an export value so when an account is selected the number is automatically populated, something like this:
Itemlist.setItems([["-Select Production Account-",""],["Purchases Design Consumables","710001"],["Production Consumables - Roll","710100"]]);
Copy link to clipboard
Copied
Hi, thanks for the reply.
I had already done what you've suggested for the dropdown fields - I'll leave as is as it works although it takes some time to load each field in "Expense Account Description" once "Department" is selected.
For the calculations: I had already set the field calculation order as you mentioned and it still behaves the same way (not auto-updating), I also tried it in reverse just to see if it changed: you still need to click another dropdown option and then click 'yes' again in order for the correct amount to appear in the "Amount Excl." and "VAT" columns. Is there anything else I could try?
Copy link to clipboard
Copied
Please share your file.
Copy link to clipboard
Copied
...the links to the PDF, as well as the original Excel file.
Copy link to clipboard
Copied
Calculation is not updating because you use script as custom keystroke so if you select "Yes" and then change 'Account incl' you need to go back and reselect yes, so instead of custom keystroke script use this as custom calculation script:
if(event.value == "1")
this.getField("VATRow1.0").value = Number(this.getField("Amount InclRow1.0").valueAsString) / 1.15 * 0.15;
else
this.getField("VATRow1.0").value = 0;
Instead of using that big script in "Department" you could use a loop to go through all fields or set function in document level script and then call it in "Department" field, it would most likely speed up the process.
Copy link to clipboard
Copied
Hi,
I've done as you've suggested with the custom calculation script and that part works perfectly now - thanks! I don't know how to use a loop/document level script and tried researching, but not sure how to go about it. I've got the document to work as intended, although when selecting a 'department' in that dropdown list - for a large list of items - it can take up to 25 seconds to load the list. Would you be able to assist with code that may be able to quicken that part of the process? Here's the link to the latest file.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more