Prerequisites
- Products: Liquid UI WS, Liquid UI Server or Local DLL, Client Software
- Commands: openfile(), appendfile(), closefile(), readfile()
Purpose
This article guides you through creating a file in SAP and incrementing the counter using the appendfile command. To demonstrate this with a scenario, we’ll guide you through the following steps.
- Delete the image container on the SAP Easy Access screen
- Add a push button to add content to a file
- Add a function to append values to a file
- Check the file for new content
User Interface
//Create this file inside your script folder for customizing the SAP Easy Access Screen, SAPLSMTR_NAVIGATION.E0100.sjs
//Now, let's add the Liquid UI script to the above file and save it.
Customization
- Delete the image container on the SAP Easy Access screen using del().
//Deletes the Image container on the screen del("X[IMAGE_CONTAINER]");
- Add a toolbar push button Execute to initiate the testfunction process:
// Creates a toolbar push button labeled Execute pushbutton([TOOLBAR],'Execute','?',{'process':testFunction});
- Add a function to declare a variable and invoke another function, passing the strFileName parameter.
// Function to invoke another function function testFunction() { strFileName = 'counter.txt'; appendToCounterFile(strFileName); }
- Add a function to remove blank spaces.
// Function to remove blank spaces String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g,""); }
- Add a function to validate blank spaces in the string.
// Function to validate whether the variable holds a blank space or null value function isBlank(jvar){ if(typeof jvar == undefined || jvar == null || jvar == "" || jvar == void 0) return true; else return jvar.toString().trim() == ''; }
- Add a function to create a text file named counter.txt, increment the counter value, and append it to the file.
// Function that takes a file as a parameter and appends data to it function appendToCounterFile(fileName) { var lastCounter = 0; var z_counter = ''; var strBlank = ''; openfile(fileName,{"delimiter":","}); NEXT_LINE_READ:; readfile(fileName,{"z_counter":true}); if(isBlank(z_counter)) { goto END_OF_FILE; } lastCounter = parseInt(z_counter); var z_counter = ''; goto NEXT_LINE_READ; END_OF_FILE:; closefile(fileName); openfile(fileName,{"append":true, "delimiter":","}); lastCounter++; appendfile(fileName,{"lastCounter":true}); closefile(fileName); }
SAP Process
- Refresh the SAP Easy Access screen and click the Execute push button to increment the last value and append it to the file.