cancel
Showing results for 
Search instead for 
Did you mean: 

How to set businessKey to sub process when use the call activity?

ssun
Champ on-the-rise
Champ on-the-rise
The call activity can pass input variables from parent to child process, but I want to set the businessKey of the child process to query it easily.
Currently I can set the businessKey as a variable of the child process and query on that but it is not the real businessKey and the query is a complicated POST instead of a simple GET.

What can I do to make this happen?

Thank you very much!

–Gordon
6 REPLIES 6

trademak
Star Contributor
Star Contributor
Good point. We can make this available as a new attribute on the call activity. Could you raise a JIRA for this?

Best regards,

ssun
Champ on-the-rise
Champ on-the-rise
Where can I file a JIRA?

martin_grofcik
Confirmed Champ
Confirmed Champ

ssun
Champ on-the-rise
Champ on-the-rise
How do I register on the codehaus website JIRA system? Do I need to email someone?
It says:
Not a member? To request an account, please contact your JIRA administrators.

prakie
Champ in-the-making
Champ in-the-making
<java>
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;
import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;

import com.dynamic.bpm.module.purchase.entity.Purchase;

public class ProcessListenerEvent implements ExecutionListener
{
    protected final transient Logger log = Logger.getLogger(super.getClass());

    private static final long serialVersionUID = 5914272129386342550L;

    @Override
    public void notify(DelegateExecution execution) throws Exception
    {
    
        final String eventName = execution.getEventName();

        if (log.isDebugEnabled())
            log.debug(" > processlistenerevent > " + execution.getProcessBusinessKey() + " > eventName > " + eventName);

        if(execution.getEventName().equals(ProcessListenerEvent.EVENTNAME_START))
        {
            ExecutionEntity thisEntity = (ExecutionEntity) execution;
            ExecutionEntity superExecEntity = thisEntity.getSuperExecution();
            String key = "";
            // Check if this is the main process?.
            if (superExecEntity == null)
            {
                // If it is, get the business key with the main process was launched
                // with.
                //TODO use getProcessBusinessKey() from 5.15.1
            
                key = thisEntity.getBusinessKey();
               
                if(StringUtils.isEmpty(key))
                {
                 key = thisEntity.getProcessBusinessKey();
                }
               
            }
            else
            {

                // it could be caller / subprocess ; so get the BusinessKey variable set by the
                // caller.
                // This should work for N no of multi- level deep sub processes.
                key = (String) superExecEntity.getVariable("BusinessKey");
            }

            // if both the above method fails? get from the internal variable 
            final Purchase purchase = (Purchase) execution.getVariable("purchase");

            if(StringUtils.isNotEmpty(key))
            {
                // Set a process variable with the business key. Can't actually set
                // business key because business keys
                // have to be unique per process instance.
                thisEntity.setVariable("BusinessKey", key);               
            }
            else
            {
                thisEntity.setVariable("BusinessKey", purchase.getBusinessKey());
            }

            //TODO check the alternative, it's deprecated in 5.15.1 it's been removed.!!!!
            //execution.updateProcessBusinessKey(purchase.getBusinessKey());
           
           
            execution.getEngineServices().getRuntimeService().updateBusinessKey(execution.getProcessInstanceId(), key);
                       
            if (log.isDebugEnabled())
            {
             //TODO sometimes this may throw NPE, could be bcoz of this called method execution.getProcessBusinessKey()
             try
             {
              log.debug(" < update processlistenerevent > " + key + " > eventName > " + eventName +" < purchase < "+purchase.getBusinessKey() +" > processBusinessKey < "+execution.getProcessBusinessKey());
             }
             catch(NullPointerException npe){
              log.debug(" key > "+key);
             }
            
            }
               

        }
       
        if(log.isDebugEnabled()) log.debug(" < processlistenerevent < event = "+eventName);
    }

}
</java>

ssun
Champ on-the-rise
Champ on-the-rise
That is awsome prakie! I wonder when will this code change will be in the product.
Also I suspect some user would want it to be an option to whether inherit the businessKey from parent process or not.
Or someone may go crazy ask for some transformation functionality for example:
parentBusinessKey: parent1
childBusinessKey: parent1child1