Expand my Community achievements bar.

How do I increment a counter in a sub-form?

Avatar

Level 2

I have a subform that contains a field named Service_Location.  I want the value to default to 1, and increment by 1 each time I add a new instance of the subform using Designer ES-4.  I am a newbie to Designer, and do not "speak" Java.

Suggestions?

25 Replies

Avatar

Former Community Member

Hi Anokie1,

In your field Service_Location, go into the Object->Value tab, next to Default: write 1.

Then after your code that adds new instance, write this :

Service_Location.rawValue = Service_Location.rawValue + 1  (make sure formcalc is selected as the language)

If you want to make sure your have the right cell, when you are in the event editor, you can hold ctrl and click on your Service_Location cell, this way you make sure there will be no mistake. After clicking on it, the complete path will be written you simply have to add .rawValue and the rest of the instruction.

Avatar

Level 2

MTremblay-Savard,

Thank you for your response.  I just have two questions.

When you said, "

Then after your code that adds new instance, write this :

Service_Location.rawValue = Service_Location.rawValue + 1  (make sure formcalc is selected as the language)," 

  1. how do I select formcalc as the language?
  2. am I looking at the XML source code?

I used the Action Builder tool to create all this.  I don't know where in the code to insert your statement.

Michael

Avatar

Former Community Member

1st : You can open the script editor palette by going in the top menu, clicking on Palettes -> Script Editor (CTRL + SHIFT + F5), when the script editor is opened, on the top right, you have a language dropdown menu, select Formcalc.
language.png

2nd : You don't need to look at the XML source code.

Can you please clarify your problem? Do you want to count it at runtime or as you create it in the designer?

Max

Avatar

Level 2

I wish the counter to increment when the "Add Service Location" is clicked by the user during runtime.

I have captured the portion of my screen that I believe is the Script Editor.  When I click on the button, there are several lines showing.  They all contain the name of my object, followed by two colons ( :: ).  These are followed by words such as

  • initialize
  • enter
  • exit
  • calculate
  • validate
  • validationState
  • mouseEnter
  • and more.

I tried to insert your statement as shown, but I get an error message.

Increment_Counter.jpg

Suggestions?

Avatar

Former Community Member

The words you listed there are the moments where your code can be triggered, you have to choose the one that apply to your problem. Personally, i'd say you would have to put your code in the click event.

click.png

Can you send the error message you're receiving please?

Max

Avatar

Level 2

Here is a screen print of the error message.

Error Message.png

Here is a screen print of the code in the script editor.

Code.png

Avatar

Former Community Member

in formcalc, there is no { } and ;

The correct syntax would be

if (xfa.host.version < 8 ) then

     Service_Location.rawValue = Service_Location.rawValue + 1

endif

Avatar

Level 2

Code and error message follows.

Code.png

Error.png

What am I missing?

Avatar

Level 2

When I use Action Builder to create a new instance of Service_Locations, it creates the following Java script and comments out the script you provided.  The script adds a new instance above  the first instance.  I want it to be added below.

  1. topmostSubform.Service_Locations.ActionButton.Add_Service_Location::click - (JavaScript, client)

//+ GENERATED - DO NOT EDIT (ID:22CE6DFD-DD76-4749-8B34-C8D33B321304 CRC:507825259)

//+ Type: Action

//+ Result2: AddInstance("$Node3")

//+ Result1: SetFieldValue("$Node2","tovalue","Alternate")

//+ Node3: topmostSubform[0].Service_Locations[0]

//+ Node2: topmostSubform[0].Service_Locations[0].Service_Location[0].Service_Location_Header[0].Service_Address_Type[0]

//+ Node1: topmostSubform[0].Service_Locations[0].ActionButton[0].Add_Service_Location[0]

//+ Condition1: Button("$Node1","click")

//+ ActionName: Add_Service_Location.click

  1. this.resolveNode("Service_Location.Service_Location_Header.Service_Address_Type").rawValue = "Alternate";
  2. this.resolveNode('topmostSubform._Service_Locations').addInstance(1);

if (xfa.host.version < 8) {

    xfa.form.recalculate(1);

}

//-

/*

  1. this.resolveNode('topmostSubform._Service_Locations').addInstance(1);

if (xfa.host.version < 8) then

    Service_Location.rawValue = Service_Location.rawValue + 1

endif

    xfa.form.recalculate(1);

*/

 

I still cannot get the counter to increment. 

Avatar

Level 7

You  have the syntax slightly wrong. In formcalc the instance manager should be:

nameOfTheThingYouAreAdding.instanceManager.addInstance()

You don't need all the action builder stuff.

MTremblay-Savard is correct on the count.

Avatar

Former Community Member

As Whyisthisme said, the problem is not on the lines i gave to you, the problem is your "this.resolveNode('topmostSubform._Service_Locations').addInstance(1);"

First, as i said there is no ; in Formcalc, so remove it. Second if you want to add an instance, do as whyisthisme said :

nameOfTheThingYouAreAdding.instanceManager.addInstance()

This should be working.

Max

Avatar

Level 2

I have tried to incorporate all of your instructions into the following code.

Code.png

However, I get the following error message.  There is not a new instance and the counter does not increment.

Error Message.png

I truly appreciate your assistance and patience.

Anokie1

Avatar

Former Community Member

There is something you are messing up.

1. The thing you want to make a new instance of and the counter should not be the same item. The counter should be an other object that only increments and that is hidden so it does not appear on your form.

2. You messed up writing the syntax, you've writen instanceManger instead of InstanceManager. In fact, not every objects have an instance manager, if you want to make sure yours have one, when you write the name of your object and the '.'(dot), you get a list of items you can choose from, if instanceManager is not in it, your object does not have an instance manager. From what i know so far, i know that text object doesn't have an instance manager, instead you should use text fields.

Max

Avatar

Level 2

I have instanceManager working now.  I caught the spelling mistake.

Here is a screenprint of the heirarchy tab of my form.

Heirarchy.png

The Service_Locations subform occupies an entire page.  When I click on the "Add_Service_Location" button, I need three events to occur.

  1. Add a new instance of the entire page.  This should push the  "Add_Service_Location" button to the bottom of the next page.
  2. Increment the Service_Location numeric field by 1.
  3. Change the value of Service_Address_Type to "Secondary". 

Is this possible?

Anokie1

Avatar

Former Community Member

Hi Anokie1,

1. Does the creation of the new instance of your page work? And i don't think you can "push" the "Add_ServiceLocation" button to the next page. You should check some information about the instance manager, it might clarify some things for you.

http://help.adobe.com/en_US/livecycle/10.0/DesignerHelp/WS92d06802c76abadb11a7f71129b8b00825-7fac.ht...

2. The incrementation should be working by now, doesn't it?

3. This is mostly like the incrementation, but instead you write :

Service_Locations.Service_Location.Service_Location_Header.Service_Address_Type.rawValue = "Secondary"

Max

Avatar

Level 2

We are getting extremely close.

  1. The Add Instance is working.  It puts the new instance on a new page as designed.
  2. The counter on page two does not increment.
  3. The value for Service.Address_Type.rawValue changes to "Secondary" on page 1 and the default "Primary" goes to page two.

Here is the script for your review.

Script.png

Thanx.

Anokie1

Avatar

Former Community Member

2. Hmm, what if we put the counter on the master page?

3. Check the documentation if there is a way to set values of certain instance of an object. example : yourthing.instance(2).rawValue = "Secondary".  Something like that.

Max

Avatar

Level 2
  1. You are asking me about putting something on a master page!  We should be asking Adobe support.  The $300 price tag for a previously-free add-on to Acrobat Pro should get better support and documentation!
  2. The documentation (lack of a searchable user guide in PDF format for Designer ES4) should be an embarrassment to Adobe.  I don't have a clue where to start.

Avatar

Level 2

Can you jump into this problem again?  I thought we were getting close.

Avatar

Former Community Member

Hahahahahaha nice one, i agree there is a huge lack of documentation. Here is this documentation about the master page.
http://help.adobe.com/en_US/livecycle/9.0/designerHelp/index.htm?content=000076.html

Do you have a vague idea of what a master page is? In gross, a masterpage is a page that contains the information that repeats over the pages, like the header or the footer. You can have multiple master pages if you want only your first page to look like something and the others like something else. In the master pages, you have something called a Content Area, this is where your Page will appear. If you want to create a master page, above your Service_Locations in your hierarchy, you should have something called (Master Pages), right click on it and click on add new master page. Do some tests on it and you'll get used to it. It might(and probably will) even be useful for what you are actually doing.

This seems to be talking about changing the value of certain instance of your object. Take some time and try to understand it.

Max