08-31-2016 8:31 PM
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.
08-31-2016 9:06 PM
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
08-31-2016 9:06 PM
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
09-06-2016 2:37 PM
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:
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!
09-06-2016 5:48 PM
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
09-06-2016 8:15 PM
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!