How to retrieve active tasks or cases relative to a BDM record by it's persistenceId

1
0
-1

Hi all,
Is there a way via REST API to retrieve all active tasks or cases relative to a BDM record, via its persistenceId?

Let me briefly explain what I have to do:

I created a process that at a certain point eliminates information (database records) that are no longer needed from the BDM.
The delete operation takes place by retrieving the BDM instance via its persistenceId and then in the "operations" of the task by setting the business variable to "is deleted". This deletion operation works perfectly, however if there are Tasks (or open cases) associated with that BDM record, the tasks (or cases) continue to exist, but obviously they are no longer able to access the BDM data which are been eliminated.

For this reason, I need to know (before allowing deleting a record from the BDM) if there are any tasks (or open cases) associated with that particular BDM record.

I would therefore need a REST API which, given a persistenceId of a BDM record, tells me if there are tasks (or open cases) associated with that DB record.

1 answer

1
0
-1

Solved as follow

Defined the following variable di UI Designer:
allTask ../API/bpm/task?p=0&c=1000 External API

that will return an array like the following:
[
{
"displayDescription": "Il procedimento è in attesa che il responsabile lo visioni ed approvi il regolamento",
"executedBy": "0",
"rootContainerId": "1004",
"assigned_date": "2023-08-03 12:10:58.477",
"displayName": "Accettazione del Regolamento da parte del Responsabile",
"executedBySubstitute": "0",
"dueDate": "",
"description": "La richiesta è assegnata al responsabile che deve prendere visione del regolameno e procedere o meno all'accettazione dello stesso",
"type": "USER_TASK",
"priority": "normal",
"actorId": "106",
"processId": "6561950334030087816",
"caseId": "1004",
"name": "Accettazione Regolamento",
"reached_state_date": "2023-08-03 12:10:58.478",
"rootCaseId": "1004",
"id": "20039",
"state": "ready",
"parentCaseId": "1004",
"last_update_date": "2023-08-03 12:10:58.478",
"assigned_id": "214"
},
......
]

Define a variable existTaskForPID as Javascript expression that do this:

async function getCaseInfo(cid)
{
var r = null;
var x = await fetch("../API/bpm/case/" + cid + "/context")
.then((response) => response.json())
.then((json) => r = json);
console.log(">>>> getCaseInfo(cid: '"+cid+"') => ",r);
return r;
}
if ( $data.allTask && $data.allTask.length && (typeof $data.richieste_selected !== 'undefined') && ($data.richieste_selected !== null) && (typeof $data.richieste_selected.persistenceId !== 'undefined') )
{
return $data.allTask.every(
async function(e, i)
{
var caseDetails = await getCaseInfo(e.caseId);
var exist = ((caseDetails && caseDetails.richiestaBDM_ref && caseDetails.richiestaBDM_ref.storageId)?(caseDetails.richiestaBDM_ref.storageId == $data.richieste_selected.persistenceId):false);
console.log(">>>> Case Info: ", i, exist);
return exist;
}
);
}
else
{
return false;
}

so if the JavaScript variable: existTaskForPID=false i can proceed with deletion of the BDM record.

This is my solution to the problem, in case it helps someone...

If you have a better solution let me know

Samuel

Notifications