Author Topic: Get Current Date  (Read 6966 times)

Benjamin Dasari

  • GuiXT Forum
  • Newbie
  • *
  • Posts: 96
    • View Profile
Get Current Date
« on: February 29, 2016, 11:11:25 AM »
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.

Liquid UI Code:

// 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){            // 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'
          call('BAPI_USER_GET_DETAIL',{'IN.USERNAME':'&V[_user]','OUT.DEFAULTS':'userDefaults'});
          dateformat = userDefaults.substring(27,28);
          z_currentformattedDate = formatDate(curDateStr,dateformat);      
     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});


See attachments for code samples!
« Last Edit: July 25, 2016, 02:46:52 PM by Benjamin Dasari »