Share ideas, ask questions, and get feedback about developing for ProcessMaker

Moderator: amosbatto

Forum rules: Please post new questions under "Developing processes & programming" for ProcessMaker 2 or 3.
#786731
You only need to use the newCase() web service if you are creating this new case outside ProcessMaker. If you are inside ProcessMaker, you can call PMFNewCase() in a trigger fired after the DynaForm.

If you can't figure it out, then post the code you are using or attach your process where you have tried to implement it.
#814129
amosbatto wrote:You only need to use the newCase() web service if you are creating this new case outside ProcessMaker. If you are inside ProcessMaker, you can call PMFNewCase() in a trigger fired after the DynaForm.

If you can't figure it out, then post the code you are using or attach your process where you have tried to implement it.

hi
i want to call startCase page in javascript in my project. but i cant do this.
i connect with PM in my project.
can you help me?
#814141
If you are in a DynaForm in ProcessMaker 3, then you can use this JavaScript code to create a new case:
Code: Select all
var 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 all
var 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
Currency Format in Textbox

I have it working but I noticed that it does not a[…]

I am having an issue with summing the values in a […]

Cancel Cases

Hello, I´m not sure if this would help with […]

Hello, The similar topic has been discussed here:[…]