Calling a Business Function

If you know the business function name and the parameters (data items) associated with the business function, you can use the dynamic Java connector to call the business function. The dynamic Java connector does not require pre-generated wrappers. This code sample shows you how to use the dynamic Java connector to call a business function:

import com.jdedwards.system.connector.dynamic.spec.SpecFailureException;
import com.jdedwards.system.connector.dynamic.ServerFailureException;
import com.jdedwards.system.connector.dynamic.Connector;
import com.jdedwards.system.connector.dynamic.spec.source.*;
import com.jdedwards.system.connector.dynamic.SystemException;
import com.jdedwards.system.connector.dynamic.ApplicationException;
import com.jdedwards.system.connector.dynamic.callmethod.*;

...//Declare Class

public void execMethod() throws SpecFailureException,ServerFailureException
{
BSFNSpecSource specSource = null;
// Step 1: Login
int sessionID = Connector.getInstance().login("user", "pwd", "env","role");

// Pre-condition: create the SpecDictionary or BSFNSpecSource
specSource = new OneworldBSFNSpecSource(sessionID);

// Step 2: Lookup the BSFN method from SpecDictionary or BSFNSpecSource
BSFNMethod bsfnMethod = (BSFNMethod)specSource.getBSFNMethod 
("GetEffectiveAddress");

// Step 3: create the executable method from the BSFN metadata
ExecutableMethod addressbook = bsfnMethod.createExecutable();
try
{

// Step 4: Set parameter values
addressbook.setValue("mnAddressNumber", "105");

// Step 5: Execute the business function
BSFNExecutionWarning warning = addressbook.execute(sessionID);

// Step 6: Get return parameter values
System.out.println("szNamealpha= " + addressbook.getValueString
("szNamealpha"));
System.out.println("mnAddressNumber= " + addressbook.getValueString
("mnAddressNumber"));
}
catch (SystemException e)
{
//SystemException is thrown when system crash, this is a fatal
//error and must be caught
System.exit(1);
}
catch (ApplicationException e)
{
// ApplicationException is thrown when business function
// execution fail, this is RuntimeException and thus can be
// unchecked. But it is strongly recommend to catch this
// exception
}
finally
{
//Log off and shut down connector if necessary
Connector.getInstance().logoff(sessionID);
Connector.getInstance().shutDown();
}
}

The dynamic Java connector permits you to use hash tables to input parameter values. This example code illustrates how to use the Hashtable class to input parameter values:

Map input = new Hashtable();
input.put("mnAddressNumber", String.valueOf(addressNo));
addressbook.setValues(input);

The dynamic Java connector permits you to use hash tables to retrieve output values. This example code illustrates how to use the Hashtable class to retrieve output values:

Map output = addressbook.getValues();
System.out.println("szNamealpha=" + output.getValueString("szNamealpha"));