Skip to Content

Is there any way to use JavaScript functions in Personas?

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.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    Posted on Aug 31, 2016 at 08: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

    Add a comment
    10|10000 characters needed characters exceeded

    • 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

  • Posted on Sep 06, 2016 at 07: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!

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.