heflo-api

HEFLO API

API (Application Programming Interface) to handle customizations on HEFLO BPM using NodeJS and Typescript.

Using npm:

$ npm install heflo-api

Performing an action on a task transition

app.post('/OnExecute', async (request, response) => {
try {
// Access all data of the process instance
let context = new Events.WorkItem.OnExecuteSequenceFlow(request);

// Your code here

// Finally, return unsaved data.
response.json(context.GetModifiedData());
} catch (err) {
response.status(500);
response.send("Error executing the request, details: " + err);
}
});

Changing the value of a field of a form

app.post('/onChanged', async (request, response) => {
try {
// Access all data of the process instance
let context = new Events.WorkItem.OnChanged(request);

// change another field
context.WorkItem.Set("OtherField", "Field changed");

// Finally, return unsaved data.
response.json(context.GetModifiedData());
} catch (err) {
response.status(500);
response.send("Error executing the request, details: " + err);
}
});

Performing the calculation of who will perform a task

app.post('/OnResourceCalculation', async (request, response) => {
try {
// Access all data of the process instance
let context = new Events.WorkItem.OnResourceCalculation(request);

// Your code here.

// Finally, return list of emails
response.json( [ "email1@mycompany.com", "email2@mycompany.com", ["name-of-department-or-group"] ] );
} catch (err) {
response.status(500);
response.send("Error executing the request, details: " + err);
}
});

Creating a new record of type Person

app.post('/OnExecute', async (request, response) => {
try {
// Access all data of the process instance
let context = new Events.WorkItem.OnExecuteSequenceFlow(request);

let person = await Person.NewAsync(context);
person.Name = context.WorkItem.Get("name_person");
person.Email = context.WorkItem.Get("email_person");
// save the record using async
await person.SaveAsync(context);

// No need to return modified data
response.json("{}");
} catch (err) {
response.status(500);
response.send("Error executing the request, details: " + err);
}
});