Skip to Content

The thing I find most exciting about SAP Screen Personas is the scripting capabilities. I see so much potential there for automation, although admittedly not all of it is realisable with the current version. I hope future versions will enhance the scripting features. In this blog I want to go through one of my scripts in some detail, which I hope will give you a good idea of what can be achieved. Scripts are recorded through the personas interface and attached to a “script button”, so that pressing the button activates the script. For the developers among you, a Personas script is essentially a BDC session except that it can be enhanced to interact with Personas-specific gui elements. You’ll see this in the example below. Let’s start with my logon screen:

/wp-content/uploads/2013/07/screenshot_243903.png

Notice the “Users” section. There’s a text field labelled “Username”, a “Lookup” button and a field labelled “Name”. The intention, obviously, is to type in a username and lookup the user’s real name. The script does this by calling transaction SU01 and grabbing data from it. This all happens in the background and the user isn’t aware of it at all. All you see is the real name appearing. Let’s look at the script step by step:

/wp-content/uploads/2013/07/screenshot_243903.png/wp-content/uploads/2013/07/screenshot_243903.png

First we “refresh” the screen. I confess I’m not clear what’s going on here, but when you copy values from screen fields a refresh is usually required. This is one of those things you “just do”, and it will appear later in this script too. Then we copy the contents of the field called “Personas/…” into a variable called “username”. These variables can be created at will and exist just for the lifetime of the script. Next we run SU01 and paste the username we just copied into the appropriate field on the first screen of that transaction. In step 6 we press the “Display” button. We’re now at the point where the user’s name is visible in SU01.
/wp-content/uploads/2013/07/screenshot_243903.png
Steps 7-9 grab the first name and last name from the screen and save them for later. Remember we need the “refresh” before copying anything from the screen. Now for the clever bit.
/wp-content/uploads/2013/07/screenshot_243903.png
First we navigate back to the login screen (press “Back” twice – I sometimes use “/n”). I wanted to present the name in a single field rather than in two, but Personas scripting has no string manipulation functions. Fortunately you can add Javascript to a Personas script, and that Javascript has access to all of the Personas script variables. So in step 12 I do some string concatenation before finally, in step 13, putting this calculated value into the relevant place back on my logon screen. After all this I now have a simple “who is this” function on my logon screen. No need to run any transactions, and while the script is running I don’t see any of the steps happening and so I’m unaware that SU01 is even involved. In use, it looks like this:

You can use scripting like this to bring data from multi-screen transactions together in one place. You can also use it to chain transactions together – replace the “save” button in one transaction with a script that performs the save and then automatically executes a follow-on transaction. I’m sure I’ll come up with many other uses for it as our Personas project unfolds.


To report this post you need to login first.

18 Comments

You must be Logged on to comment or reply to a post.

  1. Michaela Joa-Mรถhres

    Hello,

    I’m searching for a detailed documentation for this scripting.

    Has anyone an idea where to find a documentation or more detailed info about the actions?

    I’m a beginner with SAP Screen Personas.

    Thanks and Regards

    Michaela Joa-Möhres

    (0) 
    1. Steve Rumsby Post author

      There are lots of snippets of information, much in video form, here on SCN and over on the SAPScreenPersonas Wiki. It isn’t straightforward to find, though. I’ve made the same comment about the need for comprehensive scripting documentation. I don’t know if/when something will appear, though.

      In the meantime, if you have questions post them here in the SAP GUI space and I’m sure someone will try to answer them. I certainly will if I can, although I’m pretty new to it myself ๐Ÿ™‚

      Steve.

      (0) 
  2. John Astill

    Hi Steve,

    This is a great blog. I am also excited about the scripting in Personas. I’ll blog soon on the script I use to run 4 transactions to created the skeleton classes for OData development. It takes a 15 minute process and does it in seconds.

    Regards

    JohnA

    (0) 
  3. Cheryl Sutton

    Hi Steve,  I’m curious, once you capture information and store it in a variable, is there a way to look at the contents of that variable without having to paste it into a field first?

    For example,  in C# I would store user input into a variable
        firstName = “Steve”;

    Then I could use an IF to look at the firstName variable and decide what to do next.

        IF(firstName == “Steve”)

            lastName = “Rumsby”;

    Is there any such check in Personas?  It seems like you can only look at the contents of a control and not the contents of a variable.  In order to check what I have stored, I have to paste it into something like a label first, and then perform my IF on the label.

    I can post some screenshots of what I’m trying to do if this isn’t clear.

    Any insight you have would be appreciated!

    (0) 
    1. Sushant Priyadarshi

      Hi Cheryl,

      If you have the latest note implemented, then you can reference any variable with args.variable in place of control id and use it in if condition.

      Example below:

      Capture.JPG

      Regards,

      Sushant

      (0) 
      1. Abhijit Moholkar

        Hi Sushant,

        Can you please review this code snippet and suggest what is wrong with IF condition comparing variables i & limit?

        Everything else is working fine. I am comparing two variables. limit is set to 5 and i will be incremented very time I click the Script button. Their values are assigned to two screen labels and value of i is updated every time it changes. When i becomes 5, I should see label Limit Reached. But what I see is Limit not Reached in any case.

        I will paste the relevant code image as I don’t see any option to upload text files from my laptop. I have combinations like args.i equals args.limit, i equals limit, args.i equals limit but no use. Might be a minor mistake, so apologies in advance.

        IF comparison issue.PNG

        Thanks

        Abhi

        (0) 
      2. Geetha Makireddy

        Hi Sushant,

            Thanks for this example, this should help reduce a number of calls to subsequent scripts in various scenarios. ๐Ÿ™‚

        But not sure with which note this functionality came in, as we are yet to apply lastest note – 1965691. When I verified this on our system it already works which we did not make use of it thus far ๐Ÿ˜ฏ . Wondering where to look for on more specifications of symptoms(which are a bit generalized) or the new features introduced with notes ?

        Regards,

        Geetha

        (0) 
        1. Sushant Priyadarshi

          Hi Geetha,

          Well we do not add any new features in between SPs, but as you know we had a shiny new scripting engine with SP03 which gave us capability to include args.variable handling  ๐Ÿ™‚

          It was introduced probably 2-3 notes after SP03. And yes, you are right, we should have posted this somewhere. Will take care of it.

          Best Regards,

          Sushant

          (0) 
          1. Cheryl Sutton

            Awesome, implementing that note fixed the issue.  However, something else unexpected has happened.

            I’m working on a screen that has different fields that get filled in by different buttons.  Before that note, I could click buttons independently and the data would fill in and STAY filled in when I clicked other buttons.

            /wp-content/uploads/2014/01/1_370742.jpg

            Now, each time I click a button, the information that was previously retrieved by other buttons gets erased.

            2 copy.jpg

            3.PNG

            Is anyone else having this issue?  Was this ‘screen-clearing’ also part of the most current note?

            ~ Cheryl

            (0) 
            1. Steve Rumsby Post author

              This certainly doesn’t happen to me and I also have the most current note installed. Could you tell us a little more about what the scripts on the buttons are doing? That might help figure out the problem. If they’re not too long, post them here (screen grabs is the best way).

              Steve.

              (0) 
                1. Sushant Priyadarshi

                  hi Cheryl,

                  Could you please start a new discussion thread and also post you script there (including video)?

                  You can export your script in a text file and upload there.

                  Best Regards,

                  Sushant

                  (0) 
  4. Pamela Newberry

    Steve,

    I am fairly new to personas and don’t have a lot of information on scripting. 

    Can you provide help on the following:

    I created a new flavor from tcode VA22 -> Header -> sales tab.  I want to move Shipping condition (VBAK-VSBED)field  which is on the Header-> Shipping tab to my new flavor.  What does a script like that look like?

    Thanks

    Pam Newberry

    (0) 
    1. Steve Rumsby Post author

      I don’t think you need a script for that. I think this is straightforward tab merging and is described in this document – SAP Screen Personas 2.0 – How to merge tabs. I say think because we don’t use quotations so I can’t test this, but the screen looks very similar to the sales order screen which I can test…

      If you turn on tab caching and cache at least the Shipping tab, then you can move any fields from that tab to another within the tab set. The simplest way to do that is to go into edit mode while viewing the Shipping tab and drag the field and its label off the tab onto the main screen. Then drop out of edit mode, switch to the sales tab, re-enter edit mode and drag the field into its new location.

      Let me know if you need any more help with this.

      (0) 
  5. Leonardo Gajardo

    Hi,

    I’m looking for scripting documentation, about a question How managing (capture and request in IF condition) options in a Dynpro

    I’ll really preciate any answer

    Thanks

    Leo

    (0) 

Leave a Reply