Expand my Community achievements bar.

SOLVED

Odd FormCalc error on xfa.form.recalculate()

Avatar

Level 10

Using FormCalc I'm getting an accessor unknown error using xfa.form.recalculate(1).

Error: accessor 'xfa.form.recalculate("1")' is unknown.

If I take it out of the statement I have it in it and slap it on a button it works.

Statement it is in:

var vIndex = $.parent.parent.index

if (vIndex > 0) then

          Page02.subStep0203._subDiscArGr.removeInstance(vIndex)

          Page03.subStep04._subConduct.removeInstance(vIndex)

          Page03.subStep05A._subFile.removeInstance(vIndex)

          _subRespondent.removeInstance(vIndex)

          xfa.form.recalculate(1)

endif

I also get the error if I put the line outside the if statement.

I'll probably just redo it in JavaScript but generally FormCalc is much easier/faster for this sort of thing. And I'm curious as to what's happening!

1 Accepted Solution

Avatar

Correct answer by
Level 8

Hey Jono, you'll get that error if you delete the object from which is executing that script. So I'm assuming that one of those 4 subforms above your xfa.form.recalculate(1) is the parent subform of the button. It's Object suicide!

Try putting the recalculate above the line for which you delete the parent of the button and see what happens.

Kyle

View solution in original post

6 Replies

Avatar

Level 9

Hi Jono,

Are you using the script in exit ecent or change event of some fields and forcing the calculation script using recalculate() method?

Bibhu.

Avatar

Level 10

Hey Bibhu, it's on the click event of a button. Recalculate() is used elsewhere in the form without error.

In case there was corruption I made a new button and put the code on it and still get the error.

Avatar

Correct answer by
Level 8

Hey Jono, you'll get that error if you delete the object from which is executing that script. So I'm assuming that one of those 4 subforms above your xfa.form.recalculate(1) is the parent subform of the button. It's Object suicide!

Try putting the recalculate above the line for which you delete the parent of the button and see what happens.

Kyle

Avatar

Level 10

That was it! Fixed it with an execCalculate() call. Odd that I've never run into the problem before.

var vIndex = $.parent.parent.index

if (vIndex > 0) then

          Page02.subStep0203._subDiscArGr.removeInstance(vIndex)

          Page03.subStep04._subConduct.removeInstance(vIndex)

          Page03.subStep05A._subFile.removeInstance(vIndex)

          subRespondent[*].subRespNumber.execCalculate()

          _subRespondent.removeInstance(vIndex)

endif

It seems kind of counter-intuitive to put the execCalculate() before removing the subform but it turns out execCalculate() is deferred. In the blog post I found it says that recalculate() is deferred as well but it didn't seem work for me.

More info here:

http://blogs.adobe.com/lcdesigner/2008/10/script_dependencies_and_recalc.html

Avatar

Level 8

Thanks for that article. The best part about that article is John Brinkman's comment on referencing the instance manager object in a calculation event instead of using both the calculation event and the indexChange event.

Consider this, say you want a numbered list of rows that increments the number everytime you add a row. In the calculate event of a cell in the row you would put this.rawValue=this.parent.index+1;

but of course if you delete the first row it doesn't recalculate and your left with a set of rows starting with 2. Well I've always put in the indexChange event of the row NumField.execCalclulate(); to refresh the field when a row was deleted. Well try this two liner in the calculate event of the field alone without any code in the indexChange event of the row:

var i=_RepeatableRow.count; //it's only use is to trick the

//calculate event mitigating the need for indexChange event code

this.rawValue=this.parent.index+1;

Here, I inserted a 'useless' line of code (var i=_RepeatableRow.count) for the sole purpose of tricking the calculate event into thinking it's referencing the instance manager object. When the objects count property changes from the deletion of a row, it fires the event. Cool.

Kyle

Avatar

Level 10

Ah cool, yeah I tried playing with the dependency but didn't get it figured out yet.

Works great!