Service Variable results

Service variable result sets should always be obtained in the onResults, onSuccess or other service variable event.

Using service variable events ensures:

  • The service call has returned.
  • Errors returned from the service call are handled
  • The result set is available.
Always use the service variable events to access the result set.

The returned data can be accessed in JavaScript via inData parameter to the result function

Here is how to access the results of an HQL query in Javascript.

  1. Create an HQL query, say getCustomers
  2. Create a Service Variable that invokes the query, say serviceVar1
  3. Drag a button on the palette and bind the onClick event for that button to serviceVar1. This will have the same effect as calling serviceVar1.update() in Javascript and will cause the HQL query to be executed
  4. Invoke a Javascript function from the onResult event for serviceVar1. This will call a Javascript function when the HQL query returns its results.
  5. The result of the HQL query will be in the inSender parameter of the onResult function.
  6. Use the inSender.getCount() function to fine out how many rows were returned by the HQL query
  7. Use the inSender.getItem(i) to return the ith row of the query (first row is 0)
  8. Use row.data.columnName to return a particular column in a row.
The javascript code follows.

serviceVariable1Result: function(inSender, inData) {
    try {
       console.log(inSender.getData());
       var i;
       var rtnString = '';
       var numRows = inSender.getCount();
       console.log('Number of rows returned from HQL query = '+numRows);
       if (numRows > 0) {
          for (i=0; i < numRows; i++) {
             var aRow = inSender.getItem(0);
             rtnString += 'Row '+(i+1)+' '+aRow.data.contactlastname+'\n';
             alert('Contact is '+aRow.data.contactlastname);
          }
       }   
       this.largeTextArea1.setDataValue(rtnString);
    } catch(e) {
      console.error('ERROR IN serviceVariable1Result: ' + e); 
    }

To examine the inSender.getData() structure with firebug, use console.log or debugger to set a breakpoint.

The following requires a console such as firebug:

liveVariable1Result: function(inSender, inData) {
    console.log(inSender.getData());  
    debugger;      
  }

See also: Service Variables


      Share/Bookmark
© 2010 WaveMaker Software™ All Rights Reserved.