Starting a Process Instance—Service Connector API Example (Java)

Example code is provided that illustrates starting a process instance using method calls available in the Service Connector API.

The step numbers in the comments correspond to the steps in the illustration, Starting a Process Instance.

private void startProcessInstanceExample()
	{
		QualifiedProcessName process = QualifiedProcessName.Factory.newInstance();
		try
		{
			// Step 1 : List the available templates
			BasicProcessTemplate[] templates = serviceConnectorInstance.listProcessTemplates(process);
			// Step 2 : Get the starter operations, in this example we use the first template we got back
			if (templates != null && templates.length > 0)
			{
				StarterOperation[] operations = serviceConnectorInstance.listStarterOperations(templates[0]
						.getProcessQName());
				// Step 3 : Check the starter operation - in this example we use the first starter operation we got back
				if (operations != null && operations.length > 0)
				{
					OperationInfo info = serviceConnectorInstance.getStarterOperationInfo(
							templates[0].getProcessQName(), operations[0].getOperation());
					String processId = serviceConnectorInstance.createProcessInstance(templates[0].getProcessQName(),
							operations[0].getOperation(), null);
					System.out.println(processId);
				}
			}
		}
		catch (IllegalArgumentFault e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		catch (OperationFailedFault e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}