Prerequisites
- Products: Liquid UI WS, Liquid UI Server, Client Software
- Commands: inputfield(), pushbutton(), del(), return()
Purpose
To get the current date in the user-specified date format. Here, the date format is retrieved using a function module call to BAPI_USER_GET_DETAIL or from SU03 transaction. We will walk you through the following steps.
- Delete unnecessary screen elements
- Create an input field to display the current date
- Add a pushbutton to call the function that displays the current date
- Create a function to capture the date from the object, and transform it to the target format
- Create a function to change the date from 6 digits or 8 digits to the correct format
User Interface
Create this file inside your script folder for customizing SAP Easy Access screen SAPLSMTR_NAVIGATION.E0100.sjs
//Now, let's start adding the following script content to the above file.
Customization
- Open SAP Easy Access screen and delete the image container on it, as shown below:
// Deletes an image container on SAP Easy Access screen del("X[IMAGE_CONTAINER]");
- Add an input field to display the current date.
// Creates an input field with the label Date to display the date. inputfield( [1,1], "Date", [1,10],{"name":"z_currentformattedDate", "size":10});
- Add a pushbutton to call the function, when clicked.
// Creates a pushbutton with the label as Get current date to call a function, when clicked. pushbutton([4,8], "Get current date","?",{"process":getCurrentDate});
- Now, add the following Liquid UI script to this file, and save the file.
// Capture the date from object and transform it to targeting format
function getCurrentDate(){
var today = new Date();
if(today.getMonth()<9){ //getMonth returns month value from 0~11, add "0" before actual month value if is JAN~SEP(1~9)
curDateStr = today.getFullYear() + "0" + (today.getMonth()+1) + today.getDate();
} else{ //No need to add "0" if actual month value is OCT~DEC (10~12)
curDateStr = today.getFullYear() + (today.getMonth()+1) + today.getDate();
}
onscreen 'SAPLSMTR_NAVIGATION.0100'
z_currentformattedDate = formatDate(curDateStr,"2"); //For format "mm/dd/yyyy", date format in function is 2
enter('?');
}
// Change date from 6 digit or 8 digit to correct format:
function formatDate(date,dformat){
var date1 = "";
month = date.substring(4,6);
year = date.substring(0,4);
date = date.substring(6,8);
switch (dformat){
case '1':
date1 = date + "." + month + "." + year;
break;
case '2':
date1 = month + "/" + date + "/" + year;
break;
case '3':
date1 = month + "-" + date + "-" + year;
break;
case '4':
date1 = year + "." + month + "." + date;
break;
case '5':
date1 = year + "/" + month + "/" + date;
break;
case '6':
date1 = year + "-" + month + "-" + date;
break;
}
return (date1);
}
SAP Process
- Now, refresh the SAP screen, and click the Get current date pushbutton. Then, you will get today’s date displayed on the input field, as shown in the image below.