In the bot, SharedMemory allows for dynamic switch operations by saving multiple configuration files to shared memory. These files can then be accessed by two separate control files. This is similar to the switchto command in WS, which allows for the control of an operation to be switched to a specified configuration file.
We will showcase dynamic switching in the bot by creating two separate tasks. Each task will use the same guixt.sjs file but different avatar.js files with separate sets of scripts. In this article, we’ll create two tasks: setting up a notification in the iw21 transaction and creating a sales order in the va01 transaction.
- First, open the bot directory and make a copy of your avatar.js file. Name the copy 'avatar1.js'.
- Now open the original avatar.js file and enter the following line.
SharedMemory('LiquidUIAvatar').write({sjs:'C:\\fte\\fte1.sjs'});
- Here will write data from a specified file into the shared memory 'LiquidUIAvatar' that you have defined. Later, you'll create the file from which you are reading. It will essentially be a copy of your guixt.sjs file with a specific script directory defined. Each bot instance will read from the same shared memory, but the data read will be different since the source files are not the same.
- 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.
- Now open the guixt.sjs file and enter the following line to define the source file.
var avatar = SharedMemory('LiquidUIAvatar').read(); switchto = [avatar];
- To enable dynamic switching, create a variable and set its value as the identifier of the shared memory where your source files are stored. The file guixt.sjs reads this shared memory and executes the data called by the source sjs file. You can store multiple files here, not just two.
- Create two different sets of scripts for creating a notification and sales order. In our example, we will have one set of scripts that will create a notification and one to create a material. Both sets can utilize the same elogon file; however, the function called in elogon will differ. An elogon file for the IW21 file is shown below.
load('C:\\guixt\\functions.sjs'); set("F[User]", "user"); set("F[Password]", "12345"); enter("process":create_iw21);
Note: Generic functions are stored in 'functions.sjs'. They can be placed anywhere, even in the elogon file, as we’ll demonstrate in later examples. - Create two copies of your guixt.sjs file in the bot directory. Name the first one as 'fte1.sjs' and the second as 'fte2.sjs'. Open the 'fte1.sjs' file and enter the directory where the script for the IW21 operation is stored. In our example, the directory is as shown below.
directory1 = "C:\\guixt\\fte1";
- Close the 'fte1.sjs' file and open the 'fte2.sjs' file. Enter the directory where the script for the VA01 operation is stored. In our example, the directory is as shown below. Save your changes and close the file.
directory1 = "C:\\guixt\\fte2";
- Open the 'functions.sjs' file and create a function for the IW21 transaction. The 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'); }
- Similarly create a function for the VA01 transaction in function.sjs file. 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); } }
- Save the changes and close the script file.
- 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
- Schedule a second task in Windows Task Scheduler to run the avatar1.js file. Set this task to run between the times your initial task is scheduled. For example, if the first task runs at 1 AM, 3 AM, and 5 AM, schedule the second task to run at 2 AM and 4 AM.
guixt4webapp.exe -f avatar1.js
- Now run both tasks and verify the correct process for each task by checking SAP for the new record numbers.