Filling a field with the contents of another field only when a condition is fulfilled

Community Beginner ,
Mar 24, 2020 Mar 24, 2020

Copy link to clipboard

Copied

I am developing a PDF to aid in completing forms necessary for the expungement of criminal records. Most defendants have more that one case. Some have many more. Each PDF contains numerious petitions  each followed by  related order. Every 4 pages of the PDF  a  new petition and its related order begins.

Among other things, each petition and order has a Text field ("P1.Case.CaseNum") for the  number of the case (which may be numbers and letters) and a drop down menu for the county of the court in which the case happened.

One particular county requires a separate  document that lists all the case numbers of the cases from that county (That County's dropdown output is 056.) I have added this listing document to the end of the PDF.

 

I want a script for a field in  this listing document that copies the case number from a petition only if the county involved is 056.

 I have the following script that will ener Jefferson (if 056 is chosen in the dropdown) or Blank if  it is not.

 

if((this.getField("P1.Case.County").value == "056")) this.event.value = "Jefferson" else this.event.value = " Blank"

 

What I can't do is replace "Jeferson" with something that will produce the case  number that is entered in "P1.Case.CaseNum text" box of a petition. I think I have tried every conceiveable possible combination and have run out of ideas.

 

Thank you.

TOPICS
Acrobat SDK and JavaScript

Views

235

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

correct answers 1 Correct Answer

Adobe Community Professional , Mar 24, 2020 Mar 24, 2020
If you want the value of the field to be determined solely based on the value of the drop-down then your addition is fine.

Likes

Translate

Translate
Adobe Community Professional ,
Mar 24, 2020 Mar 24, 2020

Copy link to clipboard

Copied

You have errors in your code, but since it's not the code you need to use anyway that's not important.

In order to keep the text field editable you need to move your code to the drop-down field, specifically to its Validation event.

There you can place something like this:

 

if (event.value=="056") this.getField("P1.Case.CaseNum text").value = "Jefferson";

 

You can duplicate this line of code multiple times if needed. For example:

if (event.value=="057") this.getField("P1.Case.CaseNum text").value = "Washington";

if (event.value=="058") this.getField("P1.Case.CaseNum text").value = "Lincoln";

etc.

This will make sure that the text field is updated if one of those items is selected, while keeping it free for the user to manually change it, if needed.

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 ,
Mar 24, 2020 Mar 24, 2020

Copy link to clipboard

Copied

Sorry I wasn't clear. 

I don't want the word "Jefferson" in the field. It appears in a field in the petititon.

 

I want a case number to appear both in the petition and in a separate form which is the last page of the PDF when, and only when, the case is from Jefferson (output 056)

 

It is a third field "Re-Ordeer Test" in the last page of the PDF that I want to fill with the same number that was placed in the "P1.Case.CaseNum" test box inthe petition. Jefferson only appears in the pulldown menu box in the petition and order.

 

Again I appologize for misleading you.

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
Adobe Community Professional ,
Mar 24, 2020 Mar 24, 2020

Copy link to clipboard

Copied

What's the name of the drop-down field?

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 ,
Mar 24, 2020 Mar 24, 2020

Copy link to clipboard

Copied

Thnaks for getting back to me.

 

P1.Case.County

 

I  Modified a state form. You can see an original petition on the web at at https://kycourts.gov/resources/legalforms/LegalForms/4962.pdf 

 

More background-- Each case requires one petition and one proposed order. (4 pages).  In addition to the petitions and orders that the courts and every county reuire, Jefferson County (no. 056 - KY has 120 counties - can you believe that) also requires a form  listing  the case numbers of the cases (petitions and order) that are being submitted at one time.  Most of the the cases I handle are from Jefferson County, but not all defendants are  homebodies. I have joined 10 pairs in one pdf (40 pages) and added the Jefferson county list form. It is not unusual to have 6 cases from Jefferson and 1 from some other county.

 

What I have done is have adobe put all case numbers on the Jefferson county form  by using the same fields that are used in the forms, and then after the form is printed, cross out the case numbers that relate to a county other than jefferson.

 

Thanks again

 

 

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
Adobe Community Professional ,
Mar 24, 2020 Mar 24, 2020

Copy link to clipboard

Copied

As the custom calculation script of "Re-Ordeer Test", enter the following code:

 

if (this.getField("P1.Case.County").valueAsString=="056") event.value = this.getField("P1.Case.CaseNum").valueAsString;

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 ,
Mar 24, 2020 Mar 24, 2020

Copy link to clipboard

Copied

To try67

I looked up valueAsString and have learned something -- We try to live life for value but it is mostly lived AsString.

 

Thanks so much. You code solved  my problem. 

 

In my prior unsucessful attempts I'd always had an "else" after the "if" clause.

I don't want to sound ungrateful, but I added a else clause back in.  Specifically,     else this.event.value = " "

My reasons --

The way the form  is set up (case number blank above countypulldown) most people will  enter  the case number and then the county.  Since most of my cases are in Jefferson County, the default setting on the county pull down is Jefferson County (or 056 as we know it)

 

By playing around I found that if there is no "else" clause and one enters the case number first, the code  will, as it should, enter the case number in the reorder list. Which is fine if the case is in Jeffereson County. But if the county is not Jefferson and I then change the county from Jefferson (after entering the case number), the case number is  not deleted from the reorder list. However if I have the "else"clause it erases the case number.

 

Again thank you. This is my first experience with the Support Community. It was almost magical. I can't tell you how much time Ispent trying different ideas.

 

No good deed goes unpunished. I'll be back.

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
Adobe Community Professional ,
Mar 24, 2020 Mar 24, 2020

Copy link to clipboard

Copied

LATEST

If you want the value of the field to be determined solely based on the value of the drop-down then your addition is fine.

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