Is there a way to load a processInstance variable in a start form?
I am trying to load some fields in a Startform that will access a processInstance variable. I think that the processInstance variable are instantiated after the Submit button is clicked on the Startform but I was wondering if there was a way around that. I need to look up the values from another REST process which complicates things a bit.
Here is what I thought would work but does not…
import org.camunda.bpm.spring.boot.starter.annotation.EnableProcessApplication;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@EnableProcessApplication(“process-camunda”)
public class ProcessCamundaApp {
public static void main(String… args) {
SpringApplication.run(ProcessCamundaApp.class, args);
}
}
public class StartEventExecutionListener implements ExecutionListener {
private final Logger logger = Logger.getLogger(StartEventExecutionListener.class.getName());
@Override
public void notify(DelegateExecution execution) throws Exception {
try {
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> config = mapper.readValue(getClass().getClassLoader().getResourceAsStream(“jsonsample.json”), Map.class);
Client client = new Client();
client.setBaseUrl((String)execution.getVariable("restUri"));
Map<String,Object> in = new HashMap<String, Object>();
in.put("value1", execution.getVariable("variable1"));
in.put("value2", execution.getVariable("variable2"));
in.put("value3", execution.getVariable("variable3"));
Map<String, Object> response = client.put(Client.AUTHENTICATIONv1, in);
logger.info(mapper.writeValueAsString(response));
int code = (int) response.get("httpResponseCode");
if(code == 201 && response.containsKey("payload")) {
Map<String, Object> out = (Map<String, Object>) response.get("payload");
UUID uuid = UUID.fromString((String) out.get("authToken"));
execution.setVariable("AuthToken", uuid.toString());
GetProfiles(uuid.toString(), execution);
execution.setVariable("success", true);
} else {
execution.setVariable("success", false);
}
} catch(Exception ex) {
logger.log(Level.ALL, ex.getMessage(), ex.getCause());
}
}
private static void GetProfiles(String AuthToken, DelegateExecution execution) throws Exception{
Client client = new Client(); //custom REST endpoint
client.setAuthenticationToken(AuthToken);
// get the available profiles
Map<String, Object>profileresponse = client.getArray("/v1/Profiles");
String profilestring = profileresponse.toString();
int responsecode = (int) profileresponse.get("httpResponseCode");
String payloadresponse = (String) profileresponse.get("payload").toString();
Map<String, String> profiles = new HashMap<String, String>();
String[] profilesarray = payloadresponse.split(",");
for (int counter = 0; counter < profilesarray.length; counter++)
{
profiles.put("Profile" + counter, profilesarray[counter].replace("[","").replace("]", "").replace("\"", ""));
}
if(responsecode == 200 && profileresponse.containsKey("payload")) {
execution.setVariable("availableprofiles", objectValue(profiles)
.serializationDataFormat(SerializationDataFormats.JSON)
.create());
}
else {
execution.setVariable("availableprofiles", "Value Not Set");
}
}
}
StartForm.html
Greetings {{ userName }}
Processing Settingsinject(['$rootScope', function($rootScope) { $scope.userName = $rootScope.authentication.name; }]);
</script>
Thanks for any assistance