Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Function call in FormCalc

Avatar

Level 2

I am trying to call a function (type4) from within a FormCalc exit event:

if ($.rawValue <> "2") then

     type4.validate()

endif

But when I run the form, I get an error saying that the "script does not have a method 'validate'."

My function definitely does have a method called 'validate', see below:

function validate() {

     [...]

}

Can anyone help me identify what I'm doing wrong? Thanks for your help.

--Bruce

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

the XFA spec states that a script can only reference a script in a document variable (alias script object), if it uses the same contentType (alias scripting language).

That's why you cannot call a JavaScript function from FormCalc.

http://partners.adobe.com/public/developer/en/xml/xfa_spec_3_3.pdf#page=377

View solution in original post

3 Replies

Avatar

Level 10

Hi,

I beleive validate() is a reserved method, so you should rename your function into validateObj() or so.

And when calling a function, the syntax looks like:

if ($.rawValue <> "2") then

     validateObj()

endif

In contrast to JavaScript FormCalc can only call functions which have been declared before the function call.

Just an example.

This script works, because the function is declared before it's called.

func alert(msg) do

          $host.messageBox(msg)

endfunc

if ($ < 2) then

          alert("value to small")

else

          alert("value ok")

endif

but this script fails, because the function call points to a function which has not be declared yet.

if ($ < 2) then

          alert("value to small")

else

          alert("value ok")

endif

func alert(msg) do

  $host.messageBox(msg)

endfunc

Avatar

Level 2

Thanks for the reply, radzmar. I'm sorry, but in reading my original post again, it seems I did not mention that my function is a Javascript function, not a FormCalc function. Does this change your response? One other potentially relevant fact is that I have the function saved in a Scripting Object at the subform level, not the form level.

In any event, I've tried renaming the function, as suggested, and even moved up the variables folder (containing the function) so that it is positioned hierarchically above the field that is calling the function, hoping that this would satisfy the requirement to declare the function it before it's called, but it still does not appear to be working. Is there anything else you can suggest? I appreciate the help.

--Bruce

Avatar

Correct answer by
Level 10

Hi,

the XFA spec states that a script can only reference a script in a document variable (alias script object), if it uses the same contentType (alias scripting language).

That's why you cannot call a JavaScript function from FormCalc.

http://partners.adobe.com/public/developer/en/xml/xfa_spec_3_3.pdf#page=377