Purpose
You want to work with a GuiXT table variable in JavaScript as an array.

Solution
You can convert the GuiXT variable to an JSON Object, modify it and convert it back.

  GuiXT table variable to JSON: JSON.parse()

  JSON Object to GuiXT variable: JSON.stringify()
 

Example:
We read all sales orders for a given customer number with BAPI_SALESORDER_GETLIST. Then we round and format the net value of each item.


GuiXT script

InputField    (5,87) "Customer"  (5,107) _
 
size=8        _
 
name="KUNNR"

 Pushbutton (5,71)       "Read sales" _
 
process="read_orders.txt" size=(2,14) 

 if V[rowsCount=]
 
set V[rowsCount] 10
endif
 

Table   (8,71)   (23,137) title="Sales" _
  name="salesorders" rows="&V[rowsCount]" 

Column "Description" table="salesorders"  _
 
-readOnly       size=40 name="SHORT_TEXT"

Column  "Price" table="salesorders"  _
  -readOnly       size=16 name="NET_VALUE"   

InputScript script

CreateStructure V[return] _
 
MESSAGE
 

// items
CreateTable
V[salesorders] _
 
MATERIAL NET_VALUE SHORT_TEXT
 

 Set V[SALESORG] "1010" 

// read order
Call
"BAPI_SALESORDER_GETLIST"   _
 
export.CUSTOMER_NUMBER="KUNNR" _
 
export.SALES_ORGANIZATION="SALESORG" _
 
import.SALES_ORDERS="salesorders" _
 
import.RETURN="return"

 Sort table="salesorders" columns="NET_VALUE" -descending 

CallJS read_sales "salesorders" 

return 

 

JavaScript

unction read_sales(mytable) {

    // Convert GuiXT table to JavaScript object
    var myobj = JSON.parse(guixt.Get(mytable));

    /**********/
    /* Example:
    myobj = { 
               { "SHORT_TEXT":"Pump 123", "NET_VALUE":55.12 },
               { "SHORT_TEXT":"Engine XY", "NET_VALUE":4892.12 }
             };     
    */


    // For each row in the table do... 
    for (var i = 0; i < myobj.length; i++) {

        // Get the string at row i, column "NET_VALUE"
        // and convert it to a number
        var value = parseFloat(myobj[i]["NET_VALUE"]);
        
        // Round the value to an integer
        value = Math.round(value);

        // Append some text 
        text = value + " €";

        // Write the new string back to the "cell"
        myobj[i]["NET_VALUE"] = text;
    }

    // Save the number of rows
    guixt.set("rowsCount", myobj.length);

    // Convert our javascript object back to the GuiXT table variable
    var mysales = JSON.stringify(myobj);

    // Update the guixt table variable
    guixt.Set(mytable, mysales);

}

Components InputAssistant + Controls