Start process with a given instance id

Hi,

I’m trying to improve the handling of process instances via the REST api and would like to get rid of the differences resulting from processes that are started either a) directly via the webapp or b) via REST.

In a) the webapp will not set a businesskey unless generated in a listener in the start event. If set in the listener however, the generated History record will NOT have this businesskey making it hard to identify.

In b) I can of course set the business key from the outside, then everyhting works well.

But as I want to enable both means of starting processes (+execute user tasks) to have an emergency fallback, both scenarios have to work.

Question: can I somehow set the process instance id of the new instance that is started via REST? If I could, I could just use the id to identify the instances and ignore the businesskey.

Thanks,
Matt

Hi Matt,

That is not possible. ID assignment is an internal concern of the process engine and should remain that way.

Are you aware that you can programmatically generate a business key when a process start form is submitted? See this docs section: Generating a Business Key | docs.camunda.org

Cheers,
Thorben

Hi Thorben,

the best case is to use vanilla, out-of-the-box Camunda. I’ve got it working now with a combination of ProcessInstanceID and BusinessKey but its plain ugly and overcomplicated.

Instead of modifying the tasklist app, would it be possible to generate a GUID-businesskey in a custom warfile for each started process? I didn’t have a look at the SDK since I am developing in .net, but maybe thats the best solution?

Thanks,
Matt

You don’t have to modify the tasklist application itself to implement that. It is part of the form that you use to start the process and that form is part of your process application (embedded form), part of the process (generated form) or external (external form). Which approach do you use? The solution I posted applies to embedded forms.

Also, why do you want a randomly generated business key when the process instance id is exactly that?

My application uses REST to start process instances by default and doesn’t use the start form feature but its own components. In this default approach, I just set the business key and everything is fine.

However, should someone start a process using the tasklist app in an exceptional case (e.g. for bug resolution), the business key is not set. I still need my application to work with the instance created in the tasklist. Hence, I require the business key. I dislike having to generate the guid in the listener, since it is a pitfall and it doesn’t work with the history anyway.

The business key should only be generated if none was given in the start request. This way, I can always just refer to the business key - it either came from my application itself or is computed automatically.

Thanks for the clarification, that makes sense. I’m afraid I don’t know how you could implement that with the current feature set. There’s a feature request for generating a business key from Java code, see https://app.camunda.com/jira/browse/CAM-3947, to provide a proper implementation for the execution listener way (I assume you are using internal API there right now). Feel free to vote for that issue and let us know if you are interested in contributing that functionality.

Thanks for the info. I just experimented a bit with SQL Triggers. It does work in my small range of use cases that I tested but it sure is not tested properly. What do you think about this approach?

DROP TRIGGER `ruexec_setbusinesskey`;
DELIMITER //
CREATE TRIGGER `ruexec_setbusinesskey` BEFORE INSERT ON `ACT_RU_EXECUTION`     FOR EACH ROW BEGIN

IF ( NEW.BUSINESS_KEY_ IS NULL AND NEW.SUPER_EXEC_ IS NULL ) THEN 
	SET NEW.BUSINESS_KEY_ := NEW.PROC_INST_ID_;
END IF;

IF ( NEW.BUSINESS_KEY_ IS NULL AND NEW.SUPER_EXEC_ IS NOT NULL ) THEN
    SET NEW.BUSINESS_KEY_ := (SELECT BUSINESS_KEY_ FROM ACT_RU_EXECUTION     WHERE ID_ = NEW.SUPER_EXEC_ LIMIT 1);
END IF;

END
//


DROP TRIGGER `hiprocinst_setbusinesskey`;
DELIMITER //
CREATE TRIGGER `hiprocinst_setbusinesskey` BEFORE INSERT ON `ACT_HI_PROCINST`     FOR EACH ROW BEGIN

IF ( NEW.BUSINESS_KEY_ IS NULL AND NEW.SUPER_PROCESS_INSTANCE_ID_ IS NULL )     THEN 
SET NEW.BUSINESS_KEY_ := NEW.PROC_INST_ID_;
END IF;

IF ( NEW.BUSINESS_KEY_ IS NULL AND NEW.SUPER_PROCESS_INSTANCE_ID_ IS NOT     NULL ) THEN
    SET NEW.BUSINESS_KEY_ := (SELECT BUSINESS_KEY_ FROM ACT_HI_PROCINST     WHERE PROC_INST_ID_ = NEW.SUPER_PROCESS_INSTANCE_ID_ LIMIT 1);
END IF;

END
//
1 Like

That’s a nice idea and looks fine to me. I haven’t got experience with database triggers, so I’m not able to comment if there are any runtime issues to be expected. But it’s sure worth a try.