There is another way to get that resolved with a revert parameter. General guideline from Cumulocity is that all operations has to be executed in order created on the platform. So getting one or a couple of latest operations works. Here is a code snippet for it:
const filter: object = {
deviceId: this.moId,
fragmentType: 'custom_type',
dateFrom: '1990-01-01',
revert: true,
pageSize: 1
};
const op: IOperation | undefined = (await this.operationService.list(filter)).data[0];
if (op && (op.status == OperationStatus.EXECUTING || op.status == OperationStatus.PENDING)) {
// business login goes here
}
This will return a list of at most one operation with the newest operation of the specified type for the specified device. If it is in status PENDING or EXECUTING then there is an operation, if it doesn’t exists or if it is in status SUCCESSFUL or FAILED then there is no ongoing operation. This works for single devices because devices are responsible to execute operations in order.