Liquid UI - Documentation - 5.2 Using SharedMemory Variables with bot

5.2 Using SharedMemory Variables with bot


This example of bot in action will demonstrate how to use SharedMemory by the simple process of automating the logon and logoff. We are using the SharedMemory feature to place a variable, which we then check to see if an action is or is not performed - in this case, to determine whether we perform a logoff. We also use SharedMemory to write a variable and create an infinite loop of this action in SAP. The steps to demonstrate this process are as follows.

  1. Create a new script file and name it 'elogon.sjs'. This file will run at logon and will contain the user logon credentials. The logon file also loads the file that will contain all the functions used in these examples. As described earlier in this document, we have created a file called 'functions.sjs' and placed it in the script directory we specified in the guixt.sjs file. Within the elogon file, we are using the WS 'set' command to send a specific username and password to SAP. Once these credentials are sent, the actions triggered by the elogon file are complete. The example code is as follows.
    load('C:\\guixt\\functions.sjs');
    set("F[User]",  "user"); 
    set("F[Password]", "12345"); 
    enter();
    

    Note: We defined the full path of the 'functions.sjs' file because we will be calling it from a different directory in a later example. You do not need to define the full path if you are calling the file from the same directory.

  2. Since no processes are contained in the elogon file, the next file that is read will be the Easy Access screen. Open the script file for the Easy Access screen (SAPLSMTR_NAVIGATION.E0100.sjs). Create the script file if it does not already exist. We will call the function in this script file as shown below.
    enter({process:run_infinite_LogonLoop}); 
  3. Save your changes and close the Easy Access script file. Now create a new file called 'functions.sjs'. This file should reside in your script directory and this is where you will place all the functions that you will use for your examples. Now open the 'functions.sjs' file and create a function that will perform the following operations.
    • Delete all existing screen elements on the Easy Access screen
    • Execute a graceful exit

    The example code is as follows.

    function run_infinite_logonLoop() { 
     del('X[IMAGE_CONTAINER]');
     image([0,0],'GuiXT.jpg'); 
    
     if(SharedMemory('WS').read().autoexit)  
      enter('/i', {process:answeryes});
    
      function answeryes(){   
       onscreen 'SAPLSPO1.0100'
       enter('=YES');    
       SharedMemory('avatar').write({loop:true});  
     } 
    }
    

    This function performs several actions. First, it removes all existing elements from the Easy Access screen in SAP, since that is the screen for which we are writing a custom script. Then it performs a test to see if the variable 'autoexit' is present for the shared memory 'WS'.If the variable exists, the function reads the state, and then executes accordingly.

    Note: The 'autoexit' variable is defined in the avatar.js file and should not be edited by users. This variable specifies whether or not a process will exit gracefully or become stuck in the event of a problem. There are two states - true and false. The 'true' state specifies a graceful exit, while the 'false' state causes the process to freeze or become stuck. The 'false' state could be useful for troubleshooting should you encounter problems with your scripts. The default state is 'true'.

    If the 'autoexit' variable is present in the shared memory 'WS', then the enter command will execute, sending the exit code '/i' to SAP and also executing the function 'answeryes'. This function will click the 'Yes' button on the exit dialog box in SAP that appears following an exit command, and will then set the variable 'loop' in the shared memory 'avatar' to 'true', causing the logon - logoff process to enter an infinite loop.

    Note: The variable 'loop' is defined in the avatar.js file. Like the 'autoexit' variable in the 'WS' shared memory, this should not be changed by users.

  4. Save the changes and close the script file.
  5. Open a command prompt and navigate to the bot directory. In our example, we placed this directory on the C drive.
  6. Type the following command.
    GuiXT4webApp.exe -f avatar.js 
  7. The task will run. Since you are running the task manually, you can follow the task progress in the Console. Please note that if you run the task automatically with the Task Scheduler, the Console will not launch and there will be no progress status.

Can't find the answers you're looking for?