Return from Workflow

Hi

  1. If validateRequest failes then i am returning a value(Not throwing exception ).In this case i dont want workflow to go to PlaceRequest and Save Request
  2. Similarly if PlaceRequest failes then i am returning a value(Not throwing exception ).In this case i dont want workflow to go to Save Request.

How to handle the above scenario

enter image description here

Sample code

@Service
public class ValidateRequest implements JavaDelegate {
	


	@Override
	public void execute(DelegateExecution execution) throws Exception {
		

		
		Request req  = (Request) execution.getVariable("req");
		
		
		if( !validate(req) ) //if validate(req) is false i should return from here and not execute subsequent workflows
		{
		
			return;
		}
		
	}

You could use a boundary error event.


You can trigger it in your code

1 Like

Hey @my_camunda_profie_1!
You can either cover this logic by throwing a BPMN error from within you code or by adding a decision after your service task.

Option A:
image

Option B:

Thanks .Will try

Oh damn, you were faster :eyes: :smiley:

1 Like

@Niall IN case i throw BPMN error from Valid Request.It will go to save request in your workflow?

Yes, if you throw a BPMN error from your code and you have an error boundary event attached to the task as i did in my model - the process will continue to the save request task

2 Likes