Prerequisites
- Products: Liquid UI WS, Liquid UI Server or Local DLL, Client Software
- Commands: inputfield(), pushbutton(), set()
Purpose
You will learn how to remove the padded values from a string value entered in an inputfield. We will walk you through the following steps.
- Delete unnecessary elements
- Add two inputfields
- Add two pushbuttons
- Add a function to remove the padded values from a source
- Add a function to remove the padded values from the left
- Add a function to remove the padded values from the right
//Create this file inside your script folder for customizing SAP Easy Access screen SAPLSMTR_NAVIGATION.E0100.sjs
//Now let's start adding the content to the above file
- Delete the image container on the SAP Easy Access screen.
//Deletes an image container on the screen del("X[IMAGE_CONTAINER]");
- Add two inputfields, namely Enter Value and New Value to enter value in the inputfield and display the value after removing the padded zeroes to left or right.
//Creates an input field with a label as Enter Value inputfield([1,0], "Enter Value", [1,16], {"size":10, "name":"z_value"}); //Creates an input field with a label as New Value and it is non-editable inputfield([2,0], "New Value", [2,16], {"size":10, "name":"z_unpadded_value", "readonly":true});
- Add two pushbuttons, namely Remove Zeroes Left, and Remove Zeroes Right to execute the required function on click.
//Creates a pushbutton with a label as Remove Zeroes Left and executes the removeZeroesLeft function on click pushbutton([4,0], "Remove Zeroes Left", {"process":removeZeroesLeft, "size":[1,18]}); //Creates a pushbutton with a label as Remove Zeroes Right and executes the removeZeroesRight function on click pushbutton([4,20], "Remove Zeroes Right", {"process":removeZeroesRight, "size":[1,18]});
- Add a function unPadZeroes to remove zeroes in the entered field value.
// Function to remove zeroes padded to the source based on the direction specified function unPadZeroes(source,direction) { var output = ""; var sourceLength = 0; var sourceOriginalLength = 0; source = source.toString(); if(source) { sourceOriginalLength = source.length; sourceLength = source.length; } switch (direction){ case "LEFT": for (var loop = 0; loop < sourceOriginalLength; loop++) { if(source[0]=='0'){ source = source.substring(1,sourceLength); sourceLength = source.length; } else { break; } } break; case "RIGHT": for (var loop = 0; loop < sourceOriginalLength; loop++) { if(source[sourceLength-1]=='0'){ source = source.substring(0,sourceLength-1); sourceLength = source.length; } else { break; } } break; } return source; }
- Add a function to remove zeroes padded on the left of the field value.
// Function to remove zeroes to the left of the source function removeZeroesLeft(){ z_temp = unPadZeroes(z_value,"LEFT"); set('V[z_unpadded_value]','&V[z_temp]'); return; }
- Add a function to remove zeroes padded on the right of the field value.
// Function to remove zeroes to the right of the source function removeZeroesRight(){ z_temp = unPadZeroes(z_value,"RIGHT"); set('V[z_unpadded_value]','&V[z_temp]'); return; }
- Enter the value in the Enter Value input field. Click Remove Zeroes Left pushbutton to remove zeroes padded left to the value entered and display it in the New Value field.
- Enter the value in the Enter Value input field. Click Remove Zeroes Right pushbutton to remove zeroes padded right to the value entered and display it in the New Value field.
Next Steps
Return values from new session
Learn how to return values from one session to another session.
Learn how to return values from one session to another session.
10 min.
This article is part of the Invoking functions tutorial.