Prerequisites
- Products: Liquid UI WS, Liquid UI Server, Client Software
- Commands: inputfield(), pushbutton(), set()
Purpose
Learn how to convert milliseconds into days/hours/minutes/seconds. We will walk you through the following steps.
- Delete an Activex container
- Add two input fields
- Add a pushbutton
- Add functionality to convert milliseconds
//Create this file inside your script folder for customizing the SAP Easy Access screen: SAPLSMTR_NAVIGATION.E0100.sjs
//Now let's start adding the content to the above file
- Delete an Activex container on the SAP Easy Access screen.
//Deletes an image container del('X[IMAGE_CONTAINER]');
- Add two inputfields namely, Enter time in milliseconds and Milliseconds converted to.
//Creates an input field to enter the time in milliseconds inputfield([1,0], "Enter time in milliseconds", [1,28], {"size":10, "name":"z_milliseconds"}); //Creates an input field which is non editable and assigns time after converting milliseconds into seconds or minutes or hours or days in the inputfield. inputfield([2,0], "Milliseconds converted to ", [2,28], {"size":10, "name":"z_converted_ms", "readonly":true});
- Add a pushbutton as Convert milliseconds.
//Creates a pushbutton to execute a process convertMilliseconds on click. pushbutton([3,7],"@01@Convert milliseconds", "?", {"process":convertMilliseconds});
- Add functionality to convert the millisecond's value into the seconds or minutes or hours or days based on the value entered in the inputfield.
Enter the time in milliseconds and click ConvertMilliseconds.// Function to convert milliseconds to Days/Hours/Minutes/Seconds depending on milliseconds value
function timeConversion(millisec) {
var seconds = (millisec / 1000).toFixed(2);
var minutes = (millisec / (1000 * 60)).toFixed(2);
var hours = (millisec / (1000 * 60 * 60)).toFixed(2);
var days = (millisec / (1000 * 60 * 60 * 24)).toFixed(2);
if (seconds < 60) {
return seconds + " Sec";
} else if (minutes < 60) {
return minutes + " Min";
} else if (hours < 24) {
return hours + " Hrs";
} else {
return days + " Days"
}
}
function convertMilliseconds(){
var res = timeConversion(z_milliseconds);
set('V[z_converted_ms]','&V[res]');
return;
}
- You will see the time converted into either seconds or minutes or hours or days based on the millisecond's value.
Next Steps
Validate Japanese Half-Width(Hankaku) Katakana Character
Learn how to convert time entered in an input field in milliseconds to Days/Hours/Minutes/Seconds.
Learn how to convert time entered in an input field in milliseconds to Days/Hours/Minutes/Seconds.
10 min.
This article is part of the Take a deep dive into the input field and pushbutton tutorial.