Purpose:
To get the future date in the current user's date format based on the number of days entered.
Liquid UI Code:
// SAPLSMTR_NAVIGATION.E0100.sjs
// Validate if the variable holds blank or null value
function isBlank(jvar){
if(typeof jvar == 'string'){
jvar = jvar.trim();
}
return(jvar == 'undefined' || jvar == null || jvar == "" || jvar == void 0);
}
// 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);
}
// Get future date based on the number of days
function getFutureDate(){
if(isBlank(z_days)) {
return('E: Enter number of Days');
}
onscreen 'SAPLSMTR_NAVIGATION.0100'
var curr_date = new Date();
curr_date.setMilliseconds(curr_date.getMilliseconds()+(z_days*24*60*60*1000));
var tmp_cur_month = curr_date.getMonth();
var tmp_cur_date = curr_date.getDate();
var tmp_cur_year = curr_date.getFullYear();
if(tmp_cur_month<9)
tmp_cur_month = "0"+(tmp_cur_month+1);
else
tmp_cur_month = (tmp_cur_month+1).toString();
if(tmp_cur_date<10)
tmp_cur_date = "0"+tmp_cur_date;
z_target_date = formatDate(tmp_cur_year+tmp_cur_month+tmp_cur_date,"2");
enter('?');
}
// User Interface
del('X[IMAGE_CONTAINER]'); // Delete AxtiveX Container on SAP Easy Access screen
inputfield([1,1], "No. of Days in future", [1,24], {"name":"z_days", "size":3, "required":true});
inputfield([2,1], "Date", [2,24], {"name":"z_target_date", "size":10});
pushbutton([2,36], "Get future date", "?", {"process":getFutureDate});
See attachments for code samples!