Liquid UI - Documentation - 5.3 Using Dynamic Switchto with bot

5.3 Using Dynamic Switchto with bot


The switchto command in WS enables you to switch control of an operation to a specified configuration file. In bot, you can use SharedMemory to perform dynamic switchto operations, where the content of multiple configuration files is written in the shared memory, and then accessed by two different control files. This process is demonstrated in the following example, where we will create two separate tasks of bot, which will each use the same guixt.sjs file, but which will each run a different avatar.js file and which will each have a separate set of scripts. In our example, we will have one set of scripts create a new notification in the IW21 transaction, and one set of scripts create a new sales order in the VA01 transaction.

  1. First, open the bot directory and make a copy of your avatar.js file. Name the copy 'avatar1.js'.
  2. Now open the original avatar.js file and enter the following line.
    SharedMemory('LiquidUIAvatar').write({sjs:'C:\\fte\\fte1.sjs'}); 

    What you are doing here is writing data from the specified file into the shared memory 'LiquidUIAvatar' that you have defined. You will create the file from which you are reading later - it is essentially a copy of your guixt.sjs file with a specific script directory defined. Each instance of bot will be reading from the same shared memory, but the data read will be different since the source files are not the same.

  3. Now open the avatar1.js file and enter the following line to define the source file.
    SharedMemory('LiquidUIAvatar').write({sjs:'C:\\fte\\fte2.sjs'}); 

    Each avatar.js file is now reading from a different configuration file.

  4. Now open the guixt.sjs file and enter the following line to define the source file.
    var avatar = SharedMemory('LiquidUIAvatar').read();
     switchto = [avatar]; 
    

    This line is what enables dynamic switching - you are creating a variable and setting its value as the identifier of the shared memory where the contents of your source files are stored. The guixt.sjs file reads this shared memory and executes whichever data is called by the source js file. You can have multiple files stored here, not only two.

  5. Create two different sets of scripts. In our example, we will have one set of scripts that will create a notification and one to create a material. Both sets can use the same elogon file - only the function called in elogon will be different. A sample elogon for the IW21 use case is shown below.
    load('C:\\guixt\\functions.sjs'); 
    set("F[User]",  "user"); 
    set("F[Password]", "12345"); 
    enter("process":create_iw21);
    

    Note: The 'functions.sjs' file contains the generic functions we will use in the process. These functions do not need to be placed in a designated file, but can instead be stored anywhere, including in the elogon file, as we will demonstrate in a later example.

  6. Now go to your bot directory and create two copies of your guixt.sjs file. Name the first one 'fte1.sjs' and the second one 'fte2.sjs'. Open the 'fte1.sjs' file and enter the directory where you are storing the scripts for the IW21 operation. In our example, the directory is as shown below.
    directory1 = "C:\\guixt\\fte1";
  7. Close the 'fte1.sjs' file and open the 'fte2.sjs' file. Enter the directory where you are storing the scripts for the VA01 operation. In our example, the directory is as shown below. Save your changes and close the file.
    directory1 = "C:\\guixt\\fte2"; 
  8. Open the 'functions.sjs' file and create a function for the IW21 transaction. You can use the same script that we used in our IW21 example earlier. Our sample function is as follows
    function create_iw21() {
       onscreen 'SAPLSMTR_NAVIGATION.0100' 
       enter('/niw21');
      
       onscreen 'SAPLIQS0.0100'  
       set("F[Notification type]", "M1");  
       enter(); 
    
       onscreen 'SAPLIQS0.7200' 
       set('F[Functional loc.]', '1032-ADMI');  
       set('F[Equipment]', '10000957');  
       set('F[VIQMEL-QMTXT]', 'FTE Test');  
       enter('/11'); 
    
       onscreen 'SAPLIQS0.0100' 
       if(_message) {  
        println('\n********-----------MESSAGE: '+_message); 
       } 
       enter('/nex'); // exit fcode 
       onscreen 'SAPLSPO1.0100' 
       enter('=YES');
    } 
    

    Note: The above function is explained in detail in the IW21 example earlier in this document.

  9. In the 'functions.sjs' file, create a function for the VA01 transaction. A sample transaction is shown below, but we will not cover the script details here.
    function create_va01() {
     onscreen 'SAPMV45A.0101' 
     set('F[Order Type]', 'OR');  
     set('F[Sales Organization]', '1000'); 
     set('F[Distribution Channel]', '1010 ');
     set('F[Division]', '00'); 
     enter(); 
    
     // Create Standard Order: Overview
     onscreen 'SAPMV45A.4001' 
     set('F[Sold-to party]', '1234'); 
     enter(); 
    
     // Create Standard Order: Overview
     onscreen 'SAPMV45A.4001' 
     enter('/Menu=3,2,1'); 
    
     // Create Standard Order: Header Data
     onscreen 'SAPMV45A.4002' 
     enter('=T\\03'); 
    
     // Create Standard Order: Header Data 
     onscreen 'SAPMV45A.4002' 
     enter('/3');
    
     // Create Standard Order: Overview 
     onscreen 'SAPMV45A.4001' 
     set('cell[All items,Material,1]', 'm-02');
     set('cell[All items,Order Quantity,1]', '2'); 
     enter(); 
    
     // Standard Order: Availability Control 
     onscreen 'SAPLATP4.0500' 
     enter('/6');
    
     // Create Standard Order: Overview 
     onscreen 'SAPMV45A.4001'
     enter('/2'); 
    
     // Create Standard Order: Item Data  
     onscreen 'SAPMV45A.4003' 
     enter('=T\\03');
    
     // Create Standard Order: Item Data  
     onscreen 'SAPMV45A.4003' 
     set('F[Stor. Location]', '0001');
     enter('/3'); 
    
     // Standard Order: Availability Control 
     onscreen 'SAPLATP4.0500' 
     enter('/6'); 
    
     // Create Standard Order: Overview 
     onscreen 'SAPMV45A.4001' 
     enter('/11'); 
    
     // Create Standard Order: Overview 
     onscreen 'SAPLSPO2.0101' 
     enter('=OPT1'); 
    
     onscreen 'SAPMV45A.4001' 
     if (_message){ 
     println("MESSAGE:" +_message); 
     } 
    } 
    
    
  10. Save the changes and close the script file.
  11. Create a task with Windows Task Scheduler as previously explained in the Running bot section of this document, making sure to call the original avatar.js file as shown in the following example.
    guixt4webapp.exe -f avatar.js 
  12. Create a second task with Windows Task Scheduler, but this time, call the avatar1.js file, as shown in the following example. Schedule this second task to run in the intervals between the times your original task is scheduled. In other words, if the first task is scheduled to run at 1AM, 3AM, and 5AM, schedule the second task to run at 2AM and 4AM.
    guixt4webapp.exe -f avatar1.js 
  13. Now run both of the tasks and verify that the correct process for each task runs by checking SAP for the new record numbers.

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