Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Script object in fragment not working?

Avatar

Former Community Member
I have a fragment that contains a script object and a text field. The text field's initialize event handler calls a method in my fragment's script object. Everything works fine in preview mode of the fragment.



When I create a new file and use the fragment in that file, the initialize event handler in my fragment is invoked just fine, but the method I'm trying to call in the script object in the fragment never fires. What I have looks like this:



File

- fragment



Fragment

- script object "Foo"

- someMethod()

- xfa.host.messageBox("Foo");

- text field::initialize

- xfa.host.messageBox('hello');

- Foo.someMethod();



When I preview the fragment, I get "hello" and "Foo" message boxes.



When I preview the file, I only get the "hello" message box.



Is what I'm trying to do possible?



Thanks,

Andy
3 Replies

Avatar

Former Community Member
When calling the script object that is embedded in the fragment you have to path specifically to that object. The scriptobjectName.method is not enough to find what you want. You would need FragmentName.ScriptObjectName.Method()



I tried it here and it worked.



You may want to use a script Fragment instead of using an embedded script object on a fragment. The script fragment would run in the form root context and would behave like you are expecting.

Avatar

Former Community Member
Hi Paul,



Thanks for the quick response. For the script fragment approach, would I insert the script fragment into the file, or can I put it in my content fragment?



Thanks,

Andy

Avatar

Former Community Member
Put it in the file so that it is at the root of the file. It will act like any other fragment (the designer cannot edit it unless they have access to the fragment source) and it will be resolved when the form is rendered, so any updates are picked up right away.