Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Benjamin Dasari

Pages: 1 ... 4 5 [6] 7
76
Purpose:
Convert milliseconds to Days/Hours/Minutes/Seconds depending on milliseconds value.

Liquid UI Code:

// SAPLSMTR_NAVIGATION.E0100.sjs

// 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;
}

// User Interface
clearscreen();
inputfield([1,0], "Enter time in milliseconds", [1,28], {"size":10, "name":"z_milliseconds"});
inputfield([2,0], "Milliseconds converted to ", [2,28], {"size":10, "name":"z_converted_ms", "readonly":true});
pushbutton([3,7],"@01@Convert milliseconds", "?", {"process":convertMilliseconds});


See attachments for code samples!

77
Purpose:
To validate each cell in an excel spreadsheet to check if it is blank or NULL.


Liquid UI Code:

// SAPLSMTR_NAVIGATION.E0100.sjs
// User Interface - SAP Easy Access Screen
load('wsoffice');   // Need to load this file to display File Selection pop-up
pushbutton([TOOLBAR],"@8T@Validate Excel", "/nMM01", {"process":testExcelCellValidation});

// Remove blank spaces
String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,'');}

// 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);
}

// Function to Show File Open Dialog
function selectFileDialog(szPrompt){ 
    if(szPrompt==void 0)
      szPrompt = 'Select Excel File';
    var dialog = new ActiveXObject('MsComDlg.CommonDialog'); 
    // dialog.Filter='All Files(*.*)|*.*'; 
    dialog.Filter='(*.xl*)|*.xl*';  // BD
    dialog.MaxFileSize=32767; 
    //dialog.AllowMultiSelect = true;
    dialog.DialogTitle=szPrompt;
    dialog.Flags=0x200|0x80000|0x800|0x4|0x200000 
    dialog.ShowOpen(); 
    //var ret = dialog.FileTitle;
    var ret = dialog.FileName;
    dialog = void 0;
    return ret;


// Function to open Excel File From The File Selection Dialog
function openExcel(filename) {
    if(excelObj == void 0)
      excelObj = new ActiveXObject('Excel.Application');
    excelBook = excelObj.Workbooks.Open(filename);
    excelObj.Visible = true;
    excelObj.ScreenUpdating = true;
}

function testExcelCellValidation(){
   OPEN_EXCEL_FILE:;
    if(excelObj == void 0) {
       excelFileName = selectFileDialog('Select Excel File');
      if(excelFileName.length) {
         openExcel(excelFileName);
         excelSheet = excelBook.ActiveSheet;
      } else {
         message('E: No Excel File Selected');
         return;            // If Problem opening selected excel file, stop the process
      }
   } else {               // Excel is already open (Manually Opened or Re-run for Error Processing)
      try {
         excelSheet = excelBook.ActiveSheet;
         // Check to see if we can read cell value, if not then Re Open Excel File
         var cellCheckValue = excelSheet.Cells(1, 2).Value;   
      }
      catch(err) {
         delete excelObj;
         goto OPEN_EXCEL_FILE;
      }
   }
   
   // Required columns
   arrReqCol = ['1','2','3'];
   nCurrentRow = 2;   
   
   if(!xlsCellDataValidation(excelSheet,nCurrentRow,arrReqCol,'A')) {
      message('E: Missing Required Values');
      return;
   } else{
      message('S: Validation successful');
   }   
}

//strCheck = 'A' - To check for Blank and NULL
//strCheck = 'N' - To check for NULL Only
function xlsCellDataValidation(excelActiveSheet, nCurrentRow, arrColumns, strCheck) {
   nCurrentRow = parseInt(nCurrentRow);
    errorColumnNo = 0;
   var z_valChk = '';
   var validData = true;               
   for(var j=0; j<arrColumns.length;j++) {
      var nCurrentCol = arrColumns[j];
      nCurrentCol = parseInt(nCurrentCol);
      // Check for both Blank and NULL Values
      if(strCheck == 'A') {
         z_valChk = excelActiveSheet.Cells(nCurrentRow, nCurrentCol).Value;
         if(isBlank(z_valChk) || z_valChk.toString().toUpperCase() == "NULL") {      
            errorColumnNo = nCurrentCol;
            validData = false;
            break;
         }
      }
      // Check for NULL Values Only
      if(strCheck == 'N') {
         z_valChk = excelActiveSheet.Cells(nCurrentRow, nCurrentCol).Value;
         if(isBlank(z_valChk)) {
         } else {
            if(z_valChk.toString().toUpperCase() == "NULL") {
               errorColumnNo = nCurrentCol;
               validData = false;
               break;
            }
         }
      }
   }   
   return validData;
}


See attachments for code samples!

78
Purpose:
To determine the data rows and columns from user selected Excel file.


Liquid UI Code:

// SAPLSMTR_NAVIGATION.E0100.sjs
// User Interface - SAP Easy Access Screen
load('wsoffice');   // Need to load this file to display File Selection pop-up
clearscreen();
inputfield([1,0], "Excel Rows", [1,15], {"size":3, "name":"z_mm01_rows"});
inputfield([2,0], "Excel Columns", [2,15], {"size":3, "name":"z_mm01_cols"});
pushbutton([4,0],"@0V@Read Excel", "?", {"process":excelRowColumnCount});

// Remove blank spaces
String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,'');}

// To 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);
}

// Function to Show File Open Dialog
function selectFileDialog(szPrompt){ 
    if(szPrompt==void 0)
      szPrompt = 'Select Excel File';
    var dialog = new ActiveXObject('MsComDlg.CommonDialog'); 
    // dialog.Filter='All Files(*.*)|*.*'; 
    dialog.Filter='(*.xl*)|*.xl*';  // BD
    dialog.MaxFileSize=32767; 
    //dialog.AllowMultiSelect = true;
    dialog.DialogTitle=szPrompt;
    dialog.Flags=0x200|0x80000|0x800|0x4|0x200000 
    dialog.ShowOpen(); 
    //var ret = dialog.FileTitle;
    var ret = dialog.FileName;
    dialog = void 0;
    return ret;


// Function to open Excel File From The File Selection Dialog
function openExcel(filename) {
    if(excelObj == void 0)
      excelObj = new ActiveXObject('Excel.Application');
    excelBook = excelObj.Workbooks.Open(filename);
    excelObj.Visible = true;
    excelObj.ScreenUpdating = true;
}

// Determine Total Number of Columns with Data in Excel SpreadSheet
function determineNoOfDataColumns(excelActiveSheet, nColumnHeadingRow) {
   var excelColumnCount = excelActiveSheet.Columns.Count;
   for(var i = 1; i<excelColumnCount;i++) {
      if (excelActiveSheet.Cells(nColumnHeadingRow, i).Value == undefined || typeof(excelActiveSheet.Cells(nColumnHeadingRow, i).Value) == 'undefined') {
         break;
      }
   }
   return i;
}

// Determine Total Number of Rows with Data in Excel SpreadSheet
function determineNoOfDataRows(excelActiveSheet, nTotalDataColumns, nStartDataRow) {
   var excelRowCount = excelActiveSheet.Rows.Count;
   for(var i = nStartDataRow; i<excelRowCount;i++) {
      lastRowFound = false;
      for(var j = 2; j<nTotalDataColumns;j++) {
         if (excelActiveSheet.Cells(i, j).Value == undefined || typeof(excelActiveSheet.Cells(i, j).Value) == 'undefined') {
            lastRowFound = true;;
         } else {
            lastRowFound = false;
            break;
         }
      }
      if(lastRowFound == true) {
         // Last Row with Data + 1;
         break;
      }
   }
   return i;
}

// Function to determine rows and columns
function excelRowColumnCount(){
   OPEN_EXCEL_FILE:;
    if(excelObj == void 0) {
       excelFileName = selectFileDialog('Select Excel File');
      if(excelFileName.length) {
         openExcel(excelFileName);
         excelSheet = excelBook.ActiveSheet;
      } else {
         message('E: No Excel File Selected');
         return;            // If Problem opening selected excel file, stop the process
      }
   } else {               // Excel is already open (Manually Opened or Re-run for Error Processing)
      try {
         excelSheet = excelBook.ActiveSheet;
         // Check to see if we can read cell value, if not then Re-Open Excel File
         var cellCheckValue = excelSheet.Cells(1, 2).Value;   
      }
      catch(err) {
         delete excelObj;
         goto OPEN_EXCEL_FILE;
      }
   }
   
   totalDataColumns = determineNoOfDataColumns(excelSheet,1);
   totalDataRows = determineNoOfDataRows(excelSheet,totalDataColumns,1);
   totalDataColumns = totalDataColumns-1;
   totalDataRows = totalDataRows-1;
   set('V[z_mm01_rows]','&V[totalDataColumns]');
   set('V[z_mm01_cols]','&V[totalDataRows]');
}


See attachments for code samples!

79
WS aka Web Scripts (Attended RPA for SAP) / Update SAP from Excel
« on: May 18, 2016, 02:41:33 PM »
Purpose:
To read from user selected Excel file and update in standard SAP fields.


Liquid UI Code:

// SAPLSMTR_NAVIGATION.E0100.sjs
// User Interface - SAP Easy Access Screen
load('wsoffice');   // Need to load this file to display File Selection pop-up
pushbutton([TOOLBAR],"@8T@Update SAP from Excel", "/nMM01", {"process":testUpdateSAPFromExcel});

// Remove blank spaces
String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,'');}

// 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);
}

// Check if a control exists or not
function isControl(str) {
   return Reebok(str).isValid;
}

// Function to Show File Open Dialog
function selectFileDialog(szPrompt){ 
    if(szPrompt==void 0)
      szPrompt = 'Select Excel File';
    var dialog = new ActiveXObject('MsComDlg.CommonDialog'); 
    // dialog.Filter='All Files(*.*)|*.*'; 
    dialog.Filter='(*.xl*)|*.xl*';  // BD
    dialog.MaxFileSize=32767; 
    //dialog.AllowMultiSelect = true;
    dialog.DialogTitle=szPrompt;
    dialog.Flags=0x200|0x80000|0x800|0x4|0x200000 
    dialog.ShowOpen(); 
    //var ret = dialog.FileTitle;
    var ret = dialog.FileName;
    dialog = void 0;
    return ret;


// Function to open Excel File From The File Selection Dialog
function openExcel(filename) {
    if(excelObj == void 0)
      excelObj = new ActiveXObject('Excel.Application');
    excelBook = excelObj.Workbooks.Open(filename);
    excelObj.Visible = true;
    excelObj.ScreenUpdating = true;
}

function testUpdateSAPFromExcel(){
   OPEN_EXCEL_FILE:;
    if(excelObj == void 0) {
       excelFileName = selectFileDialog('Select Excel File');
      if(excelFileName.length) {
         openExcel(excelFileName);
         excelSheet = excelBook.ActiveSheet;
      } else {
         message('E: No Excel File Selected');
         return;            // If Problem opening selected excel file, stop the process
      }
   } else {               // Excel is already open (Manually Opened or Re-run for Error Processing)
      try {
         excelSheet = excelBook.ActiveSheet;
         // Check to see if we can read cell value, if not then Re Open Excel File
         var cellCheckValue = excelSheet.Cells(1, 2).Value;   
      }
      catch(err) {
         delete excelObj;
         goto OPEN_EXCEL_FILE;
      }
   }
   
   onscreen 'SAPLMGMM.0060'   
      updateSAPFromExcel(excelSheet,2,1,4);   // Updates Industry sector, Material Type and Copy from Material
      enter();                        // Select Views pop-up is displayed   
}

// Applicable to only edit field and check box
// For Table and Radio button different logic applies
function updateSAPFromExcel(excelActiveSheet, nCurrentRow, nStartColumn, nEndColumn) {
   excelColumnSAPHeadingsRow = 1;
   var scrElementName = '';
   var scrElementValue = '';
      
   for(var currentCol = nStartColumn; currentCol < nEndColumn; currentCol++) {
      scrElementName = excelActiveSheet.Cells(excelColumnSAPHeadingsRow,currentCol).Value;
      scrElementValue = excelActiveSheet.Cells(nCurrentRow,currentCol).Value;

      println('\n------------ scrElementName:'+scrElementName+':');
      println('\n------------ scrElementValue1:'+scrElementValue+':\n');

      if(scrElementValue == undefined || typeof(scrElementValue) == 'undefined' || isBlank(scrElementValue)) {
         scrElementValue = '';
         continue;         // Next Element within for loop
      }
      
      if(isControl('F['+scrElementName+']')){
         // if(scrElementValue.trim() == 'NULL'){
         if(scrElementValue.toString().trim().toUpperCase() == 'NULL'){
            set('F['+scrElementName+']','');                           //set the value to blank
         } else {
            set('F['+scrElementName+']','&V[scrElementValue]');               //set the value to user entered value in excel
         }
      } else if(isControl('C['+scrElementName+']')){
         // if(scrElementValue.trim() == 'NULL'){
         if(scrElementValue.toString().trim().toUpperCase() == 'NULL'){
            set('C['+scrElementName+']',' ');                           //set the value to blank
         } else {
            set('C['+scrElementName+']','X');                           //set the value
         }
      } 
   }
}


See attachments for code samples!

80
Purpose:
To copy the contents of a text file to the clipboard by executing a function on UIEvent/s.


Liquid UI Code:

// SAPLSMTR_NAVIGATION.E0100.sjs
// User Interface - SAP Easy Access Screen
pushbutton([TOOLBAR],'Copy to Clipboard', '?', {'process':copyClipBoard,'size':[1,20]})

// Copies the contents of the file to the clipboard
// Need to have webscript.dll v175 or later
function copyClipBoard() {
   // Examples:
   // system.ShellExecute('iexplore.exe','http://www.guixt.com');                       // Opens Web Browser with specified link
   // system.ShellExecute('notepad.exe');                                                            // Opens Notepad
   // system.ShellExecute('notepad.exe', 'C:\\guixt\\scripts\\filename.txt');      // Opens Specified File in Notepad
   system.ShellExecute('cmd.exe', '/C type c:\\guixt\\scripts\\test.txt|clip');
}


See attachments for code samples!

81
WS aka Web Scripts (Attended RPA for SAP) / Read Grid Selection Data
« on: April 22, 2016, 11:09:01 AM »
Purpose:
To read data from a grid screen based on user selection. On user entry of Plant and clicking the 'Grid Example' pushbutton will take the user to Grid screen to make user selection and read the Status, Total Qty and Delivered Qty fields.

Liquid UI Code:

// SAPLSMTR_NAVIGATION.E0100.sjs
// User Interface - SAP Easy Access Screen
load('grid_functions.sjs');                                                          // Loading functions file
del("X[IMAGE_CONTAINER]");
inputfield( [1,1], "Plant", [1,20], {"name":"z_coois_plant", "size":4});
inputfield( [2,1], "Status", [2,20], {"name":"z_coois_status", "readonly":true, "size":40});
inputfield( [3,1], "Total Qty", [3,20],{ "name":"z_coois_totalqty", "readonly":true, "size":16});
inputfield( [4,1], "Delivered Qty", [4,20],{ "name":"z_coois_delivqty", "readonly":true, "size":16});
pushbutton( [1,26], "Grid Example", {"process":gridExample});


// SAPLCOISOUTPUT.E0100.sjs
// Grid Display Screen
onUIEvents['/2'] = executeGridSelection();                              // When user double clicks on a selection in the first column, the function is executed
if(_transaction == 'COOIS' && z_coois_selection =='X'){
   set('V[z_coois_getselection]','X');
}


// SAPLCOKO1.E0115.sjs
// Grid Details Screen
if(z_coois_getselection == 'X'){
   set('V[z_coois_getselection]','');
   enter('/0',{"process":readGridDetails});
}


// grid_functions.sjs
// Functions File

// Function to take user input and land on grid screen in COOIS transaction
function gridExample(){
   var z_coois_msg = '';
   
   onscreen 'SAPLSMTR_NAVIGATION.0100'
      enter('/ncoois');

   onscreen 'PPIO_ENTRY.1000'
      set('F[S_WERKS-LOW]','&V[z_coois_plant]');               // Production plant
      enter('/8');
      
   onscreen 'SAPMSDYP.0010'
      set('V[z_coois_msg]','&F[MESSTXT1]');
      enter();
   
   onscreen 'PPIO_ENTRY.1000'
      if(z_coois_msg){
         message('E:'+z_coois_msg);
         enter('/n');
         goto FUNC_END;
      }
      enter('?');   
   FUNC_END:;         
}

// Function to set a flag on the Grid Display screen to avoid infinite loop on auto-enter
function executeGridSelection(){
   set('V[z_coois_selection]','X');
}

// Function to read information from Grid Details screen based on user selection on Grid Display
function readGridDetails(){
   onscreen 'SAPLCOKO1.0115'
      set('V[z_coois_status]','&F[CAUFVD-STTXT]');                 // Status
      set('V[z_coois_totalqty]','&F[CAUFVD-GAMNG]');             // Total Qty
      set('V[z_coois_delivqty]','&F[CAUFVD-GWEMG]');            // Deliv. Qty
      enter('/n');
}


See attachments for code samples!

82
WS aka Web Scripts (Attended RPA for SAP) / Get Future Date
« on: April 01, 2016, 05:54:56 PM »
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!

83
Purpose:
To create a connection to an external Database from SAPGUI and interact with it and close the connection.

Liquid UI Code:

//***********************************************
// ESESSION.sjs
// Loading Files on new session
//***********************************************
load('wsodbc');


//***********************************************
// SAPLSMTR_NAVIGATION.E0100.sjs
// User Interface
//***********************************************
del('X[IMAGE_CONTAINER]');                   // Delete ActiveX Container on SAP Easy Access screen
pushbutton([TOOLBAR],'Open DB','?',{'process':procOpenDB})
pushbutton([TOOLBAR],'Execute SQL','?',{'process':procExecute})
pushbutton([TOOLBAR],'Close DB','?',{'process':procCloseDB})

var dbName ={server:'SQLSVRNAME',dbname:'TESTDB',user:'sa',pass:'mypwd'};    // Database Connection String
dbConnectTo = dbName;
if(!db) {
   db = null;
}


// Function to establish connection to Database based on parameters
function ODBCconnect(dbase)   {   
// var sConnectTrusted = 'Driver={SQL Server Native Client 10.0};Server={'+dbase.server+'};Database={'+dbase.dbname+'};Trusted_Connection=Yes';
// var sConnectUser = 'Driver={SQL Server Native Client 10.0};Server={'+dbase.server+'};Database={'+dbase.dbname+'};UID={'+dbase.user+'};PWD={'+dbase.pass+'}';
    var sConnectTrusted = 'Driver={SQL Server};Server={'+dbase.server+'};Database={'+dbase.dbname+'};Trusted_Connection=Yes';
    var sConnectUser = 'Driver={SQL Server};Server={'+dbase.server+'};Database={'+dbase.dbname+'};UID={'+dbase.user+'};PWD={'+dbase.pass+'}';
   
   println("sConnectTrusted: ",sConnectTrusted);
   println("sConnectUser: ",sConnectUser);
    var sConnect = '';

    if(dbase.user) {
      sConnect = sConnectUser;
   } else {
      sConnect = sConnectTrusted;
   }
    println('Connect String Used: ' + sConnect);
    try{
      var dbObj = new Odbc(sConnect);
   }
   catch(err){
      message("E: Error with Database Connectivity" + err.description);
      return NULL;
   }
   
   println('\nConnected Successfully to '+dbObj.dbms+'. Server '+dbase.server+' Database '+dbase.dbname);
 
    return dbObj;
}


// Function to Open Database Connection
function procOpenDB() {      
    if(!db) {
      println('Opening session database...');
        db = ODBCconnect(dbConnectTo);
   }
}


// Function to execute commands/scripts once the connection is established
function procExecute() {   
    if(db) {
      println('DB Details:'+db.dbms);
      var strSQL = "select * from usertbl";
      for record <- db.exec('select username from usertbl') {
         println(record['username']);
      }
   } else {
      return('E: Database Connection/Reference Lost');
   }
}


// Function to Close Database Connection
function procCloseDB() {   
    if(db) {
      println('Closing ODBC Connection');
      db = null;
   }
}


See attachments for code samples!

84
Purpose:
To reference the multiple selection pop-up for a field that is available and displayed on different screens.

Liquid UI Code:

//***********************************************
// SAPLSMTR_NAVIGATION.E0100.sjs
// User Interface
//***********************************************
del('X[IMAGE_CONTAINER]');                   // Delete ActiveX Container on SAP Easy Access screen
inputfield([1,1], "Purchasing Document", [1,25], {"size":10, "name":"z_vl10g_podocnum"});
inputfield([1,45], "to", [1,60], {"size":10, "name":"z_vl10g_podocnumto"});
pushbutton([1,75], "@1E\\QMultiple selection for Purchase Orders@", "/nVL10G", {"process":multipleselection,
   "using":{"l_tab":"PO","l_selection":"=%00210300000713501","l_field":"purchasedoc"}});   // Purchase Orders Tab


// Function to pull up the multiple selection pop-up
function multipleselection(param){
   onscreen 'RVV50R10C.1000'             // General Data Tab             
      if(param.l_tab == 'PO'){
         enter('=S0S_TAB5');              // Purchase Orders Tab            
      }

   onscreen 'RVV50R10C.1000'           // Purchase Orders Tab                       
      clearscreen();                           // To hide the screen background
      if(param.l_selection == '=%00210300000713501'){
         enter(param.l_selection);
      }

   RECHECK_POPUP:;
   onscreen 'SAPLALDB.3000'            // Popup for multiple selection
      goto RECHECK_POPUP;

   onscreen 'RVV50R10C.1000'             // Purchase Orders Tab                              
      if(param.l_field == 'purchasedoc'){
         set("V[z_vl10g_podocnum]", "&F[ST_EBELN-LOW]");               // Purchasing Document Number
         set("V[z_vl10g_podocnumto]", "&F[ST_EBELN-HIGH]");          // Purchasing Document Number to   
      }
      enter('/n');                   // Back to SAP Easy Access Screen   
}


See attachments for code samples!

85
Purpose:
To differentiate between the Purchase Order Create, Change and Display screens and Purchase Requisition screens since they can be accessed from 6 different transactions such as ME21N, ME22N, ME23N, ME51N, ME52N, ME53N.

Liquid UI Code:

//***********************************************
// SAPLSMTR_NAVIGATION.E0100.sjs
// User Interface
//***********************************************
del('X[IMAGE_CONTAINER]');      // Delete AxtiveX Container on SAP Easy Access screen
box([1,1],[7,36], "Purchase Order/Purchase Requisition");
pushbutton([2,3], "ME21N", '/nME21N', {'size':[1,15]});
pushbutton([4,3], "ME22N", '/nME22N', {'size':[1,15]});
pushbutton([6,3], "ME23N", '/nME23N', {'size':[1,15]});
pushbutton([2,20], "ME51N", '/nME51N', {'size':[1,15]});
pushbutton([4,20], "ME52N", '/nME52N', {'size':[1,15]});
pushbutton([6,20], "ME53N", '/nME53N', {'size':[1,15]});

//***********************************************
// SAPLMEGUI.E0014.sjs
// User Interface
//***********************************************
if(   _transaction == 'ME21N' || _transaction == 'ME22N' || _transaction == 'ME23N' ||
   _transaction == 'ME51N' || _transaction == 'ME52N' || _transaction == 'ME53N' ) {

   // Differentiate between Purchase Order(PO) and Purchase Requisition(PR) screens
   if(<'F[Doc. date]'>.isValid) {                                 // PO Transaction
      if(!<'F[Doc. date]'>.isprotected) {                     // Create PO Transaction
            // Create PO Interface Code goes here
            title(_title + ' - Liquid UI Screen');
            del('P[Personal Setting]');   // Toolbar Pushbutton
            del('F[Vendor]');
      } else {                                       // Change or Display PO Transaction
         if(<'P[Check]'>.isValid) {                        // Change PO Transaction
            // Change PO Interface Code goes here
         } else {                                    // Display PO Transaction
            // Display PO Interface Code goes here
         }
      }
   } else {
            // PR Transaction
   }
}


See attachments for code samples!

86
Purpose:
To remove all the empty rows in a list and move the populated rows in Order.

Liquid UI Code:

// SAPLSMTR_NAVIGATION.E0100.sjs

// Function is called to remove blank spaces
String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,'');}

// Function is called to 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);
}

// Move next available item in the list to blank row
function updateRows(){
   for(var i=1;i<z_endrow;i++){
      set('V[z_temp_mat]','&V[z_material_&V]');
      set('V[z_temp_qty]','&V[z_quantity_&V]');
      z_temp_mat = z_temp_mat.trim();
      z_temp_qty = z_temp_qty.trim();
      
      // Make Material required if Quantity is entered
      if((isBlank(z_temp_mat)) && (!isBlank(z_temp_qty))){
         return("E: Please enter Material for Item: "+i);
      }
      
      // Make Quantity required if Material is entered
      if((!isBlank(z_temp_mat)) && (isBlank(z_temp_qty))){
         return("E: Please enter Quantity for Item: "+i);
      }
         
      if((isBlank(z_temp_mat)) && (isBlank(z_temp_qty))){
         for(var j=i+1; j<z_endrow; j++){
            set("V[z_temp_next_mat]", "&V[z_material_&V[j]]");
            set("V[z_temp_next_quan]", "&V[z_quantity_&V[j]]");
            z_temp_next_mat = z_temp_next_mat.trim();
            z_temp_next_quan = z_temp_next_quan.trim();
            
            if(!isBlank(z_temp_next_mat) && !isBlank(z_temp_next_quan)){
               // Copy the available item to blank row
               set("V[z_material_&V]","&V[z_temp_next_mat]");
               set("V[z_quantity_&V]","&V[z_temp_next_quan]");
               
               // Set the location to be blank
               set("V[z_material_&V[j]]", " ");
               set("V[z_quantity_&V[j]]", " ");
               break;
            }
         }
      }
   }
}

// User Interface
del('X[IMAGE_CONTAINER]');      // Delete ActiveX Container on SAP Easy Access screen
del('P[User menu]');
del('P[SAP menu]');
del('P[SAP Business Workplace]');
del('P[Display role menu]');
del('P[Add to Favorites]');
del('P[Delete Favorites]');
del('P[Change Favorites]');
del('P[Move Favorites down]');
del('P[Move Favorites up]');
del('P[Create role]');
del('P[Assign users]');
del('P[Documentation]');

z_endrow = 12;                              // Update row count here
comment([1,1], "Item   Material          Quantity");      
for(item_counter=1; item_counter<z_endrow; item_counter++){         // Display 10 rows on UI
   inputfield([item_counter+1,1], {"name":"z_item_&V[item_counter]", "size":4, "readonly":"true", "alignright":"true", "nolabel":"true"});
   inputfield([item_counter+1,6], {"name":"z_material_&V[item_counter]", "size":18, "nolabel":"true"});      
   inputfield([item_counter+1,25], {"name":"z_quantity_&V[item_counter]", "size":10, "nolabel":"true"});
   set("V[z_item_&V[item_counter]]", item_counter);
}

pushbutton([TOOLBAR], "@0Z@Update Rows", '?', {"process":updateRows});   


See attachments for code samples!

87
WS aka Web Scripts (Attended RPA for SAP) / 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!

88
Purpose:
To update SAP multiple Item fields dynamically based on re-sized screen display. The number of rows would vary based on the screen size and the script should update based on displayed SAP rows and then click on new items to populate the next set.

Liquid UI Code:

// SAPLSMTR_NAVIGATION.E0100.sjs

// Purpose: Function is called to remove blank spaces
String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,'');}

// Purpose: Function is called to 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);
}

// Purpose: Function is called to update SAP multiple Item Fields Dynamically based on re-sized screen display
function mb1a_update(){
   var z_mb1a_relrow = 1;
   var z_mb1a_absrow = 1;
   var z_mb1a_material_total_counter = 0;
   
   if(isBlank(z_mb1a_docdate)){
      return('E: Enter Document Date');
   }
   if(isBlank(z_mb1a_postdate)){
      return('E: Enter Posting Date');
   }
   if(isBlank(z_mb1a_mvmttype)){
      return('E: Enter Movement Type');
   }
   if(isBlank(z_mb1a_plant)){
      return('E: Enter Plant');
   }
   if(isBlank(z_mb1a_sloc)){
      return('E: Enter Storage Location');
   }
   if(isBlank(z_mb1a_costctr)){
      return('E: Enter Cost Center');
   }
   
   // Below logic to check and validate Material and Quantity fields
   for(var i=1;i<z_endrow;i++){
      set('V[z_temp_mat]','&V[z_mb1a_material_&V]');
      set('V[z_temp_qty]','&V[z_mb1a_quantity_&V]');
      z_temp_mat = z_temp_mat.trim();
      z_temp_qty = z_temp_qty.trim();
      
      // Make Material required if Quantity is entered
      if((isBlank(z_temp_mat)) && (!isBlank(z_temp_qty))){
         return("E: Please enter Material for Item: "+i);
      }
      
      // Make Quantity required if Material is entered
      if((!isBlank(z_temp_mat)) && (isBlank(z_temp_qty))){
         return("E: Please enter Quantity for Item: "+i);
      }
      
      // Increment the counter if material and quantity are not all filled
      if((!isBlank(z_temp_mat)) && (!isBlank(z_temp_qty))){
         z_mb1a_material_total_counter++;
         continue;
      }
   }
   
   onscreen 'SAPLSMTR_NAVIGATION.0100'
      enter('/nMB1A');
   
   onscreen 'SAPMM07M.0400'
      set('F[Document Date]','&V[z_mb1a_docdate]');
      set('F[Posting Date]','&V[z_mb1a_postdate]');
      set('F[Movement Type]','&V[z_mb1a_mvmttype]');
      set('F[Plant]','&V[z_mb1a_plant]');
      set('F[Storage Location]','&V[z_mb1a_sloc]');
      enter();
      onerror
         message(_message);
         enter('/n');
         goto SCRIPT_END;
      
   onscreen 'SAPMM07M.0421'   
      set('F[Cost Center]','&V[z_mb1a_costctr]');
      enter();
      onerror
         message(_message);
         enter('/n');
         goto SCRIPT_END;
         
   NEW_ITEM:;         
   onscreen 'SAPMM07M.0421'   
      NEXT_MATERIAL:;
      set('V[z_temp_mat]','&V[z_mb1a_material_&V[z_mb1a_absrow]]');
      set('V[z_temp_qty]','&V[z_mb1a_quantity_&V[z_mb1a_absrow]]');
      
      if(!isBlank(z_temp_mat)){
         if(z_mb1a_relrow == 1){
            set('F[MSEG-MATNR]','&V[z_temp_mat]');      // First material field
            set('F[MSEG-ERFMG]','&V[z_temp_qty]');      // First quantity field
         } else{
            set('V[z_mb1a_cur_item_onscreen]','&F[MSEG-MATNR.&V[z_mb1a_relrow]]');
            if(!isBlank(z_mb1a_cur_item_onscreen)){
               set('F[MSEG-MATNR.&V[z_mb1a_relrow]]','&V[z_temp_mat]');   // Subsequent material fields - F[MSEG-MATNR.1]
               set('F[MSEG-ERFMG.&V[z_mb1a_relrow]]','&V[z_temp_qty]');   // Subsequent quantity fields - F[MSEG-ERFMG.1]
            } else{
               goto ENTER_ON_SCREEN;
            }
         }
         z_mb1a_relrow++;
         z_mb1a_absrow++;
         goto NEXT_MATERIAL;
      } else{
         ENTER_ON_SCREEN:;
         if(z_mb1a_relrow < 3){
            set('V[z_mb1a_last_item_onscreen]',"&F[MSEG-ZEILE]");
         } else{
            set('V[z_mb1a_last_item_onscreen]',"&F[MSEG-ZEILE."+(z_mb1a_relrow-1)+"]");
         }
      }
      enter();
      onerror
         message(_message);
         enter('/n');
         goto SCRIPT_END;

   NEXT_ITEM:;      
   onscreen 'SAPMM07M.0410'
      REPEAT_ENTER:;
      enter();
      onmessage
      if(_message.substring(0,2) == 'E:'){
         message(_message);
         enter('/n');
         goto SCRIPT_END;
      } else if(_message.substring(0,2) == 'W:'){
         goto REPEAT_ENTER;
      } else{
         goto NEXT_ITEM;
      }
      
   onscreen 'SAPMM07M.0421'
      if(_message.substring(0,2) == "E:"){
         message(_message);
         enter('/n');
         goto SCRIPT_END;
      }
      z_mb1a_last_item_onscreen = parseInt(z_mb1a_last_item_onscreen).toString();
      if(z_mb1a_last_item_onscreen == z_mb1a_material_total_counter){
         enter('?');         // Post or Save, but just doing refresh in this example
      } else{
         z_mb1a_relrow = 1;
         enter("/19");      // Click "New Item"
         goto NEW_ITEM;
      }
      onerror
         message(_message);
         enter('/n');
         goto SCRIPT_END;
         
   SCRIPT_END:;
}


// User Interface
del('X[IMAGE_CONTAINER]');      // Delete AxtiveX Container on SAP Easy Access screen
del('P[User menu]');
del('P[SAP menu]');
del('P[SAP Business Workplace]');
del('P[Display role menu]');
del('P[Add to Favorites]');
del('P[Delete Favorites]');
del('P[Change Favorites]');
del('P[Move Favorites down]');
del('P[Move Favorites up]');
del('P[Create role]');
del('P[Assign users]');
del('P[Documentation]');

inputfield([1,1], "Document Date", [1,20], {"name":"z_mb1a_docdate", "size":10, "date":true, "required":true});   
inputfield([2,1], "Posting Date", [2,20], {"name":"z_mb1a_postdate", "size":10, "date":true, "required":true});   
inputfield([3,1], "Movement Type", [3,20], {"name":"z_mb1a_mvmttype", "size":3, "required":true});            
inputfield([4,1], "Plant", [4,20], {"name":"z_mb1a_plant", "size":4, "required":true});                     
inputfield([5,1], "Storage Location", [5,20], {"name":"z_mb1a_sloc", "size":4, "required":true});            
inputfield([6,1], "Cost Center", [6,20], {"name":"z_mb1a_costctr", "size":10, "required":true});            

z_endrow = 10;
comment([8,01], "Item   Material          Quantity");      
for(item_counter=1; item_counter<z_endrow; item_counter++){         // Display 10 rows on UI
   inputfield([item_counter+8,01], {"name":"z_mb1a_item_&V[item_counter]", "size":4, "readonly":"true", "alignright":"true", "nolabel":"true"});
   inputfield([item_counter+8,06], {"name":"z_mb1a_material_&V[item_counter]", "size":18, "nolabel":"true"});      // 1157
   inputfield([item_counter+8,25], {"name":"z_mb1a_quantity_&V[item_counter]", "size":10, "nolabel":"true"});
   
   set("V[z_mb1a_item_&V[item_counter]]", item_counter);
}

pushbutton([TOOLBAR], "@0Z@Update - MB1A", '?', {"process":mb1a_update});   // Function call to update


See attachments for code samples!

89
WS aka Web Scripts (Attended RPA for SAP) / Validate Date Format
« on: February 25, 2016, 04:50:56 PM »
Purpose:
To check the validity of user entered date format by retrieving date format from SU3 transaction and comparing with user entered value.

Liquid UI Code:

// SAPLSMTR_NAVIGATION.E0100.sjs

// Purpose: Function is called to remove blank spaces
String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,'');}

// Purpose: Function is called to 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);
}

// Purpose: Function is called to validate the date
function isValidDate(date,dformat){
   switch(parseInt(dformat)){
   case 1:
      // DD.MM.YYYY
      var matches = /^\d{1,2}[.]\d{1,2}.\d{4}$/.exec(date);
      if (matches == null)    return false;
      else               return true;
      break;
   case 2:
      // MM/DD/YYYY
      var matches = /^\d{1,2}\/\d{1,2}\/\d{4}$/.exec(date);
      if (matches == null)    return false;
      else               return true;
      break;
   case 3:
      // MM-DD-YYYY
      var matches = /^(\d{1,2})-(\d{1,2})-(\d{4})$/.exec(date);
      if (matches == null)           return false;
      else               return true;
      break;   
   case 4:
      // YYYY.MM.DD
      var matches = /^\d{4}[.]\d{1,2}[.]\d{1,2}$/.exec(date);
      if (matches == null)    return false;
      else                return true;
      break;
   case 5:
      // YYYY/MM/DD
      var matches = /^\d{4}\/\d{1,2}\/\d{1,2}$/.exec(date);
      if (matches == null)           return false;
      else               return true;
      break;
   case 6:
      // YYYY-MM-DD
      var matches = /^(\d{4})-(\d{1,2})-(\d{1,2})$/.exec(date);
      if (matches == null)    return false;
      else               return true;
      break;
   }                             
}

// Retrieve Date Format and check the validity of user entered Date
function checkDateFormat(){
   if(isBlank(z_date)){
      return('E: Enter Date');
   }
   
   onscreen 'SAPLSMTR_NAVIGATION.0100'
      enter('/nSU3');
   
   onscreen 'SAPLSUU5.0100'
      enter('=DEFA');
      
   onscreen 'SAPLSUU5.0100'
      set('V[USERDATEFORMAT]','&F[USDEFAULTS-DATFM]');   // Date Format
      USERDATEFORMAT = parseInt(USERDATEFORMAT.trim());
      switch(USERDATEFORMAT) {
         case 1: {set('V[USERDATEFORMATMSG]','DD.MM.YYYY');} break;
         case 2: {set('V[USERDATEFORMATMSG]','MM/DD/YYYY');} break;
         case 3:   {set('V[USERDATEFORMATMSG]','MM-DD-YYYY');} break;
         case 4: {set('V[USERDATEFORMATMSG]','YYYY.MM.DD');} break;
         case 5: {set('V[USERDATEFORMATMSG]','YYYY/MM/DD');} break;
         case 6: {set('V[USERDATEFORMATMSG]','YYYY-MM-DD');} break;
         default: {set('V[USERDATEFORMATMSG]','*INVALID*');} break;
      }      
      enter('/N');
   
   onscreen 'SAPLSMTR_NAVIGATION.0100'
      validDate = isValidDate(z_date,USERDATEFORMAT);
      if(!validDate){
         message("E: Enter Date in " + USERDATEFORMATMSG +" Format");
      } else{
         message   ("S: Valid Date");
      }
      enter('?');
      
   FUNC_END:;
}

// User Interface
del('X[IMAGE_CONTAINER]');      // Delete ActiveX Container on SAP Easy Access screen
inputfield([1,1], "Date", [1,10], {"name":"z_date", "size":10});
pushbutton([1,23], "Validate Date", '?', {"process":checkDateFormat, "size":[1,15]});


See attachments for code samples!

90
Purpose:
On a Liquid UI inputfield, we can use the standard SAP F4 searchhelp display using the options of 'searchhelp' or 'techname'. Details on retrieving the 'searchhelp' or 'techname' options are including in the attached document with screenshots.

Liquid UI Code:

// User Interface
// SAPLSMTR_NAVIGATION.E0100.sjs

del('X[IMAGE_CONTAINER]');      // Delete AxtiveX Container on SAP Easy Access screen

inputfield([1,1], "MRP Type (using searchhelp)", [1,32], {"name":"z_mm01_mrptypesearchhelp", "size":2, "searchhelp":"H_T438A"});          // Using searchhelp option
inputfield([2,1], "MRP Type (using techname)", [2,32], {"name":"z_mm01_mrptypetechname", "size":2, "techname":"MARC-DISMM"});      // Using techname option


See attachments for code samples!

Pages: 1 ... 4 5 [6] 7