1. Create a class like the one below, containing a method for starting BPM process, using BPM Api
package<Package_Name>;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import com.sap.bpm.api.BPMFactory;
import com.sap.bpm.pm.api.ProcessDefinition;
import com.sap.bpm.pm.api.ProcessDefinitionManager;
import com.sap.bpm.pm.api.ProcessStartEvent;
import com.sap.bpm.pm.api.ProcessStartManager;
import commonj.sdo.DataObject;
import commonj.sdo.Property;
publicclass ProcessStarter {
private ProcessDefinitionManager processDefinitionManager;
private ProcessDefinition processDefinition;
private ProcessStartManager processStartManager;
private Set<ProcessStartEvent> processStartEvents;
private ProcessStartEvent processStartEvent;
public ProcessStarter(String vendor, String dcName, String processTechnicalName) {
this.processDefinitionManager = BPMFactory.getProcessDefinitionManager();
this.processStartManager = BPMFactory.getProcessStartManager();
this.processDefinition = processDefinitionManager.getActiveProcessDefinition(vendor, dcName, processTechnicalName);
}
public DataObject getProcessStartDataObject(){
this.processStartEvents = processStartManager.getProcessStartEvents(processDefinition.getId());
this.processStartEvent = processStartEvents.iterator().next();
DataObject sdo = processStartManager.createDataObjectForStartEvent(this.processStartEvent);
return sdo;
}
public URI startProcess(DataObject dataObject) throws BPMProcessStartException{
try {
return processStartManager.startProcess(this.processStartEvent, dataObject);
} catch (Exception e) {
thrownew BPMProcessStartException("Could not start process: "+ e.getMessage() , e);
}
}
}
2. Create an instance from the above class:
ProcessStarter starter = new ProcessStarter("<Vendor-Name>", "<DC-Name>", "<Process-Name>");
3. Set process input data:
DataObject startSDO = starter.getProcessStartDataObject(); DataObject processInput = startSDO.getDataObject("StartProcess"); processInput.set("engDepartment",”VALUE”); processInput.set("itemNo", “VALUE”); processInput.set("orderNo", “VALUE”); processInput.set("organization",”VALUE”); processInput.set("processType", “VALUE”); processInput.set("requestNo", “VALUE”); processInput.set("requestorId", “VALUE”); URI processInstanceId = starter.startProcess(startSDO);