Is it possible to retrieve the process variables in Camunda 8 Connectors Logic

I have a user task where in the form I have declared different variables, this user task is then connected to a custom connector, I want to retrieve all these variables in my connector logic for doing some execution. So is there a way to do it?
I understand that it is possible to retrieve one variable at a time in the custom connector property but I want to have multiple variables to fetched all together. Thanks!

Hi @Altmash_Siddique , yes it is possible to get all the variables.

        name = "myName",
        inputVariables = {}, // or omit this completely as empty array is the default
        type = "myType")
public Object execute(OutboundConnectorContext context) throws ConnectorException {
    String variablesJson = context.getVariables();
    Request request = gson.fromJson(variablesJson, Request.class);
    OtherStuff otherStuff = gson.fromJson(variablesJson, OtherStuff.class);
    Map<String, Object> variablesByName = gson.fromJson(variablesJson, new TypeToken<HashMap<String, Object>>(){}.getType());

Thanks for the reply! But over here the variablesJson is receiving the variables which are defined in the connector properties itself, but not the process variables defined in the user task.

Are you talking about process variables? I thought you should be able to get them like this. You can define Outputs on the user task to create one or multiple process variables from the ones in the user task.

Hi @Altmash_Siddique are developing an outbound or an inbound connector? The outbound connector has access to process variables via the context. Inbound connectors (currently) dont.

I am using an outbound connector in my case, but I’m not sure how can I access the process variables in my connector logic, because when I log context.getVariables(); it is just displaying the variables which are defined in the template of my connector and not all the process variables. So is there a different method to get the process variables in my connector logic?

@Altmash_Siddique you can access process variables in 2 ways:

  • Use a FEEL expression in the template of your connector and reference the process variables. See the example here (baseUrl is a process variable).

  • As mentioned above, the variables you define in the @OutboundConnector annotation determine which variables are fetched from the process instance when connector is executed (e.g. here only the caller variable will be fetched). Empty list results in all process variables being fetched. Make sure the user task defines proper outputs so that process variables are actually created.