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

Text Field Custom Calculation Script Won't Save/Stay Selected

Guest
Apr 03, 2017 Apr 03, 2017

Copy link to clipboard

Copied

I have a Text field named "MyField". I'd like to add a Custom Calculation Script to it. Every time I select the edit, enter the code, and then click OK, it does not save the code and then reselects the default "Value is not calculated" option. It will even happen in fields that I have already saved previously and that did once work. When returning to them sometimes, I will see the selection change from "Customer Calculation Script" to "Value is not calculated" as soon as I activate that Calculate tab. Does anyone have any idea what causes this and/or how to avoid/correct it. I have tried searching all over Google and can't seem to find anyone else that has brought up this issue.

TOPICS
Acrobat SDK and JavaScript , Windows

Views

2.7K

Likes

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 ,
Apr 03, 2017 Apr 03, 2017

Copy link to clipboard

Copied

I've had the same thing happen before.

Are you using the default JS editor or an external editor? And does the doc contain a large number of related fields?

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

Likes

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
Guest
Apr 03, 2017 Apr 03, 2017

Copy link to clipboard

Copied

This is while in the form through the text field properties.2017-04-03_14-45-35.jpg

Likes

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 ,
Apr 03, 2017 Apr 03, 2017

Copy link to clipboard

Copied

Huh? This doesn't really answer any of the questions asked above...

Likes

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
Guest
Apr 03, 2017 Apr 03, 2017

Copy link to clipboard

Copied

I must not have understood the question. I am scripting this through Adobe Acrobat Pro XI while in the Properties of the Text Field. I assume that is the default editor to which you are referring, but I am new(ish) to Adobe and JS. And there are definitely a large number of fields in the doc, but not many are necessarily related. All are either Text Fields or Check Boxes.

Likes

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 ,
Apr 03, 2017 Apr 03, 2017

Copy link to clipboard

Copied

The reason I asked about the editor is because Acrobat only loads the edited code when the external editor is fully closed. So you can lose a lot of entered code if your not careful how the process is handled. But this isn't your issue.

I experienced this problem when switching between fields without closing the field properties window, and also, as try67 mentions, when using the predefined operations. These predefined operations are actually just predefined JavaScript templates. I believe there is a timing issue when Acrobat opens the calculation tab, that causes the selection logic to get confused as to the actual state of the code. Acrobat sets the wrong state, which results in the code being deleted. I think it's timing because it only seems to become an issue when there are a lot of related fields that I'm switching between.

A good example of when this is a table of fields, like you'd have on an order form. In this case I'd use group naming, which puts several fields on the same AcroForm path, and I'd also use mixed calculation types, such as the "Sum" operation for the total, and a custom JS calc in other locations. And of course I'd be quickly switching between the different fields to make sure they were all setup properly. If the properties window is left open, and the field focus is switched from the sum field to a field with a JS calc, then sometimes the calculation type selection will stay the same, and the JS calc is lost.

The solution is to close the properties window before selecting another field and then reopening the properties. Try this and see if it helps.

This issue is probably more complicated than just a timing issue, and you may be experiencing it differently than I did. But it's something that has happened in several different versions of Acrobat.  I don't think they've fixed it because it's not consistently repeatable.

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

Likes

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
Guest
Apr 03, 2017 Apr 03, 2017

Copy link to clipboard

Copied

Thank you very much for that response, Thom. I have slowly been picking up Java and Adobe over the past year and really do need to get into some sort of class for it. I will take your suggestions into account moving forward. If I learn more through trial/error, I will add what I can to this thread. Do you know of any other threads already started out there that might have some other "solutions" that I should avoid repeating, haha

Likes

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 ,
Apr 03, 2017 Apr 03, 2017

Copy link to clipboard

Copied

As a matter of fact, I know exactly where you can find a wealth of information of Acrobat Scripting. But first, to be perfectly correct in our terms. The application is Acrobat, which is made by Adobe. And the internal scripting language for Acrobat is JavaScript.  Java is a completely different language, and unrelated in any way to JavaScript.  

This JavaScript is exactly the same language used in HTML.  The difference is the DOM, the Document Object Model, which is the set of objects that connect the language into the application. So the "Core" JavaScript is identical between HTML and Acrobat, but the DOM is very different. The point being that you can lean a lot about JavaScript from the tutorials at W3C, just as long as you stick to Core JavaScript. 

The top set of tutorials in the listing on the left are all core, here: JavaScript Tutorial

Here are a couple videos introductory videos on Acrobat specific JavaScript:

http://www.pdfscripting.com/public/images/Free_Videos/BeginJS_WhatsJS_Free_mp4.cfm

http://www.pdfscripting.com/public/images/Free_Videos/BeginJS_InAcrobat_Free_mp4.cfm

There also used to be a site dedicated to Acrobat users, www.acrobatusers.com

This site is no longer maintained, but all the info is still there. Here's a link to the listing of JS tutorials

https://acrobatusers.com/tutorials/filter/search&channel=tutorials&category=+13&tut_type=Video+OnDem...

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

Likes

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 ,
Apr 03, 2017 Apr 03, 2017

Copy link to clipboard

Copied

Let me first wholeheartedly recommend Thom's PDFScripting.com site. You will find a lot of really useful information on that site.

I have one other resource for you: A link to a free bock you can download and some instructions about how to use that book to learn scripting for Acrobat/PDF: Learning to Program JavaScript for Adobe Acrobat - KHKonsulting LLC

Likes

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 ,
Apr 05, 2017 Apr 05, 2017

Copy link to clipboard

Copied

I just encountered what seems to be this same problem myself, and noticed that I cannot switch the calculation type to a full script, if I select the field from the fields list - I can switch to using a script for a given field if and only if I first select that field on the document display itself (the layout window). After this is done, I seem to be able to modify the script just fine by selecting the field in the field list or in the document layout area. to anyone having this type of issue, it might be worth a try to see if that is something that helps (?)

So, the problem is when I try to select the field in the fields list, right click, select Properties > Calculate > Custom calculation script > Edit then add scripting code and click OK -- the Custom calculation script radio button is deselected and the script box is left empty.

My solution so far is to select the field in the layout display (where you position and preview the fields and document text) then right click on the field there, then select Properties > Calculate > Custom calculation script > Edit then add scripting code and click OK -- the code persists and the correct radio button remains selected. Further, once this is done, I can then select various other fields and return to this field in the field list, editing the Calculate settings and changes will persist

Certainly seems like a bug to me

Likes

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
Guest
Apr 05, 2017 Apr 05, 2017

Copy link to clipboard

Copied

I will keep this in mind, as well. Thanks, Brett!

Likes

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 Beginner ,
Oct 16, 2018 Oct 16, 2018

Copy link to clipboard

Copied

Right clicking the field in the layout view to access field properties, rather than selecting the field in the sidebar seems to make the difference for me. Unfortunate that this is still an issue, as selecting the field in the layout view risks inadvertently moving it!

Likes

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 ,
Apr 03, 2017 Apr 03, 2017

Copy link to clipboard

Copied

Yes, I've experienced it as well. Mostly when using one of the built-in functions for calculation/validation/keystroke/etc.

The code usually works, although it's not displayed in the window, though.

Likes

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
Guest
Apr 03, 2017 Apr 03, 2017

Copy link to clipboard

Copied

Yeah, I was hoping it would still work, but it doesn't seem to. It does appear to happen more often when I have multiple files open that share the same field names but are not actually connected... That is not *always* the case, though... I don't think.

Likes

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 ,
Mar 28, 2021 Mar 28, 2021

Copy link to clipboard

Copied

LATEST

I have experienced this bug in Acrobat editions after X, which is a long time for a bug to reign.  I typically use in "prepare form" properties-calclate-sum.  Frustrating.

Today, I worked around it by renaming the large number of fields automatically named in the form "undefined_99" with a shorter names.  Adobe testers, please have a look.

 

 

Likes

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