Author Topic: Get Past Date Using WS Function  (Read 3837 times)

Sai Siddhartha

  • GuiXT Forum
  • Newbie
  • *
  • Posts: 47
    • View Profile
Get Past Date Using WS Function
« on: August 10, 2017, 06:53:00 AM »
Purpose:
To get the past date in the current user's date format based on the number of days entered.

User Interface:
Log into SAP and on the SAP Easy Access Screen you will see the Liquid UI fields. Enter the 'no. of Days in past' field which is required and click on 'Get past date'.

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 past date based on the number of days
function getPastDate(){
    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 ActiveX Container on SAP Easy Access screen
inputfield([1,1], "No. of Days in Past", [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 past date", "?", {"process":getPastDate});