Liquid UI - WS Reference Library

Get Current Date


Prerequisites


Runs On

  SAP GUI Android iOS WM Web
Direct Connect          
Liquid UI Server Connect        

Purpose

To get the current date in the specified user date format and the date format can be retrieved using Function module call to BAPI_USER_GET_DETAIL or from SU3 transaction.

User Interface

Log into SAP and on the SAP Easy Access Screen you will see the Liquid UI field. Enter the date and click on ‘Validate Date’.


Liquid UI Script

//SAPLSMTR_NAVIGATION.E0100.sjs


// Capture the date from object and transform it to targeting format
function getCurrentDate(){
    var today = new Date();
    if(today.getMonth()<9){                //getMoth 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);    
}

// User Interface
del('X[IMAGE_CONTAINER]');        // Delete AxtiveX Container on SAP Easy Access screen
inputfield([1,1], "Date", [1,10], {"name":"z_currentformattedDate", "size":10});
pushbutton([1,22], "Get current date", "?", {"process":getCurrentDate});