Highlighted

Script Object (Functions) operation.

Avatar

03-11-2008


Replies

Highlighted

Avatar

03-11-2008

I have created a function called CountMeds which counts number of medications in a column of a table. I have followed all the formatting rules (including curly braces, ensuring everything is javascript, etc.). This script object exists at the highest level of the form hierarchy (created by LC). There are no errors in this script object. When I invoke CountMeds as part of a Button click script (As in CountMeds(a,b) the function is NOT executed.



What am I doing wrong?
Highlighted

Avatar

Avatar

pguerett

Total Posts

7.7K

Likes

611

Correct Answer

692

Avatar

pguerett

Total Posts

7.7K

Likes

611

Correct Answer

692
pguerett

03-11-2008

I assume the function is called CountMeds. So you would need to call the function as:



myScripObjectName.CountMeds(a,b);



If this is not it hit Ctrl-J and see what the JavaScript debugger indicates.
Highlighted

Avatar

03-11-2008

Yes the function is called CountMeds. In the Hierarchy view it shows up as part of subform "PtMedReconForm" which contains an un-renamable object called variables. It looks almost exactly like the picture in LC Designer Help under topic "Scripting > Scripting Using LiveCycle Designer ES > Creating and Reusing JavaScript Functions > To create a script object".



So in your example what would be "myScript" and what would the "ObjectName" be? Ctrl-J has no effect!



As always your rapid response and expert guidance is deeply appreciated!
Highlighted

Avatar

Avatar

pguerett

Total Posts

7.7K

Likes

611

Correct Answer

692

Avatar

pguerett

Total Posts

7.7K

Likes

611

Correct Answer

692
pguerett

03-11-2008

In the Hierarchy view click on the object, hit F2 and it will allow you to rename it. Change it to myScriptObject. Now you shoudl be able to call it by myScriptObject.CountMeds();



If that dies not work copy all of the code to the clipboard. In the hierarchy view choose the root node. Right mouse click and choose the insert script object. Now rename it as above and paste you code into this object.



Lastly, put an app.alert("This is a test") as the 1st line in the script object. Execute your button and see if the message pops up. This will tell us if the object is even being called.
Highlighted

Avatar

03-11-2008

Paul,



1. F2 button does not work!

2. I copied all the code and when I clicked on the Root node to insert script object it invariably pastes it under the same variable where it pasted CountMeds before. I can rename the newly pasted script Object but still can't rename the variable! 😞



I have put lots of app.alerts in the script to track its progress! Actually that is how I figured out that the function (script object) wasn't executing!



Once I get the function call to execute properly I think I will be on my way!



Sorry this is turning out to be such a pain but then if it had been simple I wouldn't have bothered you!
Highlighted

Avatar

Avatar

pguerett

Total Posts

7.7K

Likes

611

Correct Answer

692

Avatar

pguerett

Total Posts

7.7K

Likes

611

Correct Answer

692
pguerett

04-11-2008

The variables node cannot be renamed .....I was asking for the scriptObject to be renamed. So you should be calling your function by using scriptobjectname.functionname.



If that still does not work, post your form to livecycle8@gmail.com and I will have a look.
Highlighted

Avatar

04-11-2008

Thanks Paul! That works beautifully! I had named both the script object and the function with identical names and hence could not "see" the difference!