Calling Web Service Methods in Groovy

To invoke a web service method named someMethodName() on a web service that you registered with the variable name YourServiceVariableName, use the syntax:

adf.webServices. YourServiceVariableName . someMethodName ( args )

For instance, the example below shows how to invoke a getEmployee() method on a web service registered with the web service variable name EmployeeService, passing the integer 7839 as the single argument to the function.

// retrieve Employee object by id from remote system
def emp = adf.webServices.EmployeeService.getEmployee(7839)
// log a message, referencing employee fields with "dot" notation
println('Got employee '+emp.Ename+' with id '+emp.Empno)
// access the nested list of Dependent objects for this employee
def deps = emp.Dependents
if (deps != null) {
  println("Found "+deps.size()+" dependents")
  for (dep in deps) {
    println("Dependent:"+dep.Name)
  }
}

The code in the following example illustrates how to use Groovy's convenient Map and List construction notation to create a new employee with two nested dependents. The newEmp object is then passed as the argument to the createEmployee() method on the service.

// Create a new employee object using a Groovy map. The
// nested collection of dependents is a Groovy list of maps
def newEmp = [ Ename:"Steve",
              Deptno:10,
                 Job:"CLERK",
                 Sal:1234,
              Dependents:[[Name:"Timmy",BirthYear:1996],
                          [Name:"Sally",BirthYear:1998]]]
// Create the new employee by passing this object to a web service
newEmp = adf.webServices.EmployeeService.createEmployee(newEmp)
// The service returns a new employee object which may have  
// other attributes defaulted/assigned by the service, like the Empno
println("New employee created was assigned Empno = "+ newEmp.Empno)

The script in this example shows how to use the mergeEmployee() method to update fields in an employee object that is retrieved at the outset via another call to the getEmployee() method. The script updates the Ename field on the emp object retrieved, updates the names of the existing dependents, and then adds a new dependent before calling the mergeEmployee() method on the same service to save the changes.

// Merge updates and inserts on Employee and nested Dependents
def emp = adf.webServices.EmployeeService.getEmployee(7839)
// update employee's name to add an exclamation point!
emp.Ename = emp.Ename + '!'
def deps = emp.Dependents
// Update dependent names to add an exclamation point!
for (dep in deps) {
   dep.Name = dep.Name + '!'
}
// Add a new dependent
def newChild = [Name:"Jane", BirthYear:1997]
deps.add(newChild)
emp = adf.webServices.EmployeeService.mergeEmployee(emp)

If the web services you need to invoke expect or return data in base64 encoded format, you can use the base64-related helper functions explained in Understanding Additional Built-in Groovy Functions.