Skip to Content
author's profile photo Former Member
Former Member

Personas Table Parsing issue

Hi Experts

We are facing one issue on screen personas while table parsing to capture data selected row from the table.

We are tried using given example on SCN

Link: http://wiki.scn.sap.com/wiki/display/Img/SAP+Screen+Personas+3.0+and+Tables

Used below code:

// Define Objects

var objAdditDataBtn = session.findById("wnd[0]/tbar[1]/btn[30]"),

objMainDataBtn = session.findById("wnd[0]/tbar[1]/btn[27]"),

objAdditTable = session.findById("wnd[0]/usr/tabsTABSPR1/tabpZU01/ssubTABFRA1:SAPLMGMM:2110/subSUB2:SAPLMGD1:8000/tblSAPLMGD1TC_KTXT"),

objInfo = session.findById("wnd[0]/usr/textEditPersonas_4");

// Define Functions

// Parse data from table object to an array function

parseTable(srcTable) {

var totalColNum = srcTable.columns.length,

totalRowNum = srcTable.rowCount,

resTable = new Array();

for (var curColNum=1; curColNum<=totalColNum; curColNum++) {

var curCol = srcTable.getColumnId(curColNum);

resTable[curColNum] = new Array();

resTable[curColNum][0] = curCol;

for (var curRowNum = 0; curRowNum<totalRowNum; curRowNum++) {

resTable[curColNum][curRowNum+1] = srcTable.getCellValue

(curRowNum, curCol); } } return resTable; }

// Table data formatting function

formatTableData(srcTable) {

var resArr = [];

for (var i = 1; i < srcTable.length; i++) {

for (var j = 1; j < srcTable[i].length; j++) {

var val = srcTable[i][j].replace(/\_/g,"");

if(val) {

resArr[j] = (resArr[j]) ? resArr[j] + " " + val : val;

}

}

}

return resArr.join("\n");

}

// Parse the table and display the results

  • objAdditDataBtn.press();

var jsAdditTable = parseTable(objAdditTable),

copyData = formatTableData(jsAdditTable);

  • objMainDataBtn.press();
  • objInfo.text = copyData;

only modified screen ID’s

we are getting below error

Unexpected token {

I removed some code given only

parseTable(srcTable) {

}

For above code also I am getting same error

Please advise how to solve the issue.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Posted on Oct 09, 2015 at 02:29 PM

    I think part of the problem is that your function definitions are missing the "function" keyword. So rather than:

    formatTableData(srcTable) {   
      var resArr = [];   
      for (var i = 1; i < srcTable.length; i++) {       
        for (var j = 1; j < srcTable[i].length; j++) {           
          var val = srcTable[i][j].replace(/\_/g,"");           
            if(val) {               
              resArr[j] = (resArr[j]) ? resArr[j] + " " + val : val;         
            }    
          } 
      }   
      return resArr.join("\n");
    }
    

    you should have:

    function formatTableData(srcTable) {   
      var resArr = [];   
      for (var i = 1; i < srcTable.length; i++) {       
        for (var j = 1; j < srcTable[i].length; j++) {           
          var val = srcTable[i][j].replace(/\_/g,"");           
            if(val) {               
              resArr[j] = (resArr[j]) ? resArr[j] + " " + val : val;         
            }    
          } 
      }   
      return resArr.join("\n");
    }
    

    But also look at the code in this Wiki page to see how to copy data from a table: Copying Table data into a variable - SAP Imagineering - SCN Wiki. I'm not sure your parseTable function will work correctly.

    Steve.

    Add a comment
    10|10000 characters needed characters exceeded

    • That is correct. The object ID will say it is a "shell" but look at the type in the object inspector and it will be a TableView or GridView, like this:

      You can use the "onSelect" event of a grid or table to trigger a script. That script will be passed a "source" parameter that references the table, from which you can get the selected row number and then call getCellValue, like this:

      var row = parseInt(source.selectedRows);

      var value = source.getCellValue(row, "CCOL");

      (substitute the appropriate column name, obviously 😊)

      Does that make sense?

      Steve.

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.