If you are in a DynaForm in ProcessMaker 3, then you can use this JavaScript code to create a new case:
Code: Select allvar host = PMDynaform.getHostName(); // get the hostname
var ws = PMDynaform.getWorkspaceName(); // get the current workspace
var token = PMDynaform.getAccessToken(); // get the access Token
//var caseId = frames.app_uid ? frames.app_uid : ''; // get the case ID
var processId = "2834197345a2a09e94b2ed5000427982"; //3 ID of the process where a new case is created
var taskId = "8698940655a2a0a0c6ed945011892536"; //ID of the starting task in process
var oVarsInCase = {
"amount": 23.45,
"name": "Widgets, Inc",
"address": "2375 Southwestern Av.\nCompton NJ 27464",
"hasContract":"[1]"
}
var oPostVars = {
'pro_uid': processId,
'tas_uid': taskId,
'variables': oVarsInCase
}
$("#createCase").find("button").click( function() {
$.ajax({
url: host+"/api/1.0/"+ws+"/cases", // REST endpoint
data: JSON.stringify(oPostVars),
type: "POST",
contentType: "application/json",
//dataType: 'application/json', //set to 'text' if no response
beforeSend: function(xhr) {
xhr.setRequestHeader('Authorization', 'Bearer '+token); // Header with access token
},
success: function(xhr, status, error) {
alert("Case number: "+xhr.app_number+"\nCase ID: "+xhr.app_uid);
},
error: function(xhr, status, error) {
if (xhr.status == 400 && xhr.responseJSON) {
alert("Error: "+ xhr.responseJSON.error.message);
}
else {
alert("Error! Ready state: "+xhr.readyState+"\nHTTP status code: "+xhr.status);
}
}
});
});
Where "createCase" is the ID of a button. You have to set the IDs of the process and starting task in the code. If you want to start a case for a user who isn't the logged-in user, then you need to use the POST case/impersonate endpoint.
If you are designing an external web page, then import the jquery.js file and you can use the above code, but you will have to change the variables at the top to match your system:
Code: Select allvar host = "http://example.com"; // get the hostname
var ws = "workflow"; // get the current workspace
var token = 'XXXXXXXXXXXXXXXXX'; // use $.ajax() to login and get the access token.
See:
http://wiki.processmaker.com/3.1/OAuth_ ... ry_example