Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Is there any way to use JavaScript functions in Personas?

former_member238607
Participant
0 Kudos

Hi,

I'm new to Personas (we have 3.0) and I'm trying to develop some scripts. I have written some JavaScript functions that I would like to use in different sections of my code (for the same flavor).

I created a script named Functions and put my functions in there. They validate fine, but when I try to call them from another script, I get a undefinedReferenceError on the function name. I can call the function within the same script, so I believe this is a scope issue.

Is there anyway to share functions between different scripts? If not, how are you handling instances like this?

I also thought about making all of my code into functions, and then put them all into one script. But I don't see any way to attach a function name to an event, such as a button click. I only seem to be able to attach a script name to the event.

1 ACCEPTED SOLUTION

0 Kudos

Hi Jeff,

You can refer to the following KB article for your requirement.

Scripting: Including Global Javascript Libraries - SAP Imagineering - SCN Wiki

Also, the SAP Screen Personas Portal has several KB articles on the scripting feature and you can find them here:

Personas Knowledge Base - SAP Imagineering - SCN Wiki

Best regards

Kranthi

SAP Screen Personas Team

4 REPLIES 4

0 Kudos

Hi Jeff,

You can refer to the following KB article for your requirement.

Scripting: Including Global Javascript Libraries - SAP Imagineering - SCN Wiki

Also, the SAP Screen Personas Portal has several KB articles on the scripting feature and you can find them here:

Personas Knowledge Base - SAP Imagineering - SCN Wiki

Best regards

Kranthi

SAP Screen Personas Team

0 Kudos

Hi Kranthi,

Thank you for the response, sorry I'm late in replying, I had other issues come up at work last week.

I read the KB article and tried to implement it, but I'm still not having any luck. A couple of things I noticed in the article are:

  1. The example only shows one function. I would like to include several in my library; is that possible?
  2. I've used JavaScript a fair amount in the past, but I'm not familiar with the first line of code in the example "copyTableContents = function(sTableControlId) {". Is that a necessary format, or can I just use the standard Function [function name] format?

Below is a very simplified example of what I'd like to put into one library.

     function sayHello() {

       alert("Hello");

     }

     function sayGoodbye() {

       alert("Goodbye");

     }

If I put the following code in a script and execute it, I get an error that says sayHello is not defined..

     session.utils.include("0050545A00251DE69B84116160E823F6", true);

     sayHello();

Any ideas on what I'm doing wrong?

Thank you very much for your help!

0 Kudos

Hello Jeff,

1) Yes, it is possible to define more than one function in an include file.

2) If you want to use your library functions without "library name prefix, then, yes, you have to use syntax "functionName = function() {....} ". I personally do not like this approach because

a) this syntax defines a global variable "functionName" (attached to the window object) which lives for the entire session and which can lead to unexpected side effects if you selected names collide with standard functions or functions defined in libaries used in other flavors.

b) If you use the second approach outlined in the same KBA (see section "Usage in SAP Gui for Windows and SAP Gui for Java"), you have to access library functions via "libName.functionName()" which make your scrips much more readable IMHO ("Where did this function come from?").

Best Regards,

Clemens

former_member238607
Participant
0 Kudos

Hi Clemens,

Well, I finally got it working. You pointed me in the right direction with the second approach; I had ignored that one initially. I agree with you that it's better to fully qualify functions with the library name.

Thanks again to both of you for the help!