Expand my Community achievements bar.

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

Strange ScriptObject behavior

Avatar

Level 3

I have created a JavaScript script object that can be called from several places in my code. The weird behavior is that the JS in my ScriptObject only runs the first time I call it. Any other times and it won't be called. It also doesn't matter where it gets called first. It is always called the first time, but never on subsequent attempts. I places an alert at the very top of the ScriptObject function that I am calling. The code hits the alert the first time, but never hits it on any calls after that.

Any ideas?

- Nathan

1 Accepted Solution

Avatar

Correct answer by
Level 7

Judging from your script, it looks as though you have declared a function "count()" in your footnotes_count script object. I believe that the trouble is  "count()" is already a built-in function and therefore a reserved name(i.e. you can't use it for your function). Try renaming your function and see if that solves the problem.

Good luck!

Stephen

View solution in original post

4 Replies

Avatar

Former Community Member

1     check you have the debugger turned on, i.e. going to Reader menu, Edit->Preferences->JavaScript and check the boxes

2     if still no joy, around the script in your function, add a try catch like

function myFn () {

try

{

     your script

}

catch (e)

{

     app.alert(e);

}

} //end of function

3     if still no joy, do the same try catch thing around the calling script, e.g.

try

{

     call to your funciton

}

catch(e)

{

     app.alert(e);

}

Avatar

Level 3

OK, putting this around the actual call to the function gave the following error when the function is called a second time:

TypeError: footnotes_count.count() is not a function

Which is bizarre, because the first call to the same function worked fine.

Any ideas?

- Nathan

Avatar

Correct answer by
Level 7

Judging from your script, it looks as though you have declared a function "count()" in your footnotes_count script object. I believe that the trouble is  "count()" is already a built-in function and therefore a reserved name(i.e. you can't use it for your function). Try renaming your function and see if that solves the problem.

Good luck!

Stephen

Avatar

Level 3

I renamed the function. Looks like that solved the problem. Thanks!