How to repair a business process in hybris using groovy?

1.5k views Asked by At

I need to repair a business process so i have the OrderProcess but i don't know how to repair it using groovy. Any idea?

import de.hybris.platform.core.model.order.OrderModel
import de.hybris.platform.orderprocessing.model.OrderProcessModel


OrderModel orderModel = flexibleSearchService.search(String.format("SELECT {PK} FROM {AbstractOrder} WHERE {code} = '%s'", "P000015003")).result.get(0)

OrderProcessModel orderProcess = new OrderProcessModel();
orderModel.getOrderProcess().forEach {process ->
    if(process.getProcessDefinitionName().contains("global-order-process")){
        orderProcess = process
    }
}
2

There are 2 answers

0
Raushan Kumar On

This can be useful. order process repaired from "cancelOrderAction" node

orders.each {o ->
    def proc = o.orderProcess
    try{
        println o.code + "  --> "  + proc.processState
        def contextParameters = proc.contextParameters;
        if(contextParameters!=null){
            contextParameters
        }
        if (proc.processState != null && proc.processState.contains(ProcessState.ERROR)){

            def log = proc.taskLogs.last().last();
            String lastStep = log.actionId;
            if ((lastStep == "cancelOrderAction")) {
                defaultBusinessProcessService.restartProcess(o.orderProcess[0], lastStep);
                println o.code + "  --> "  + proc.processState + " --> " + lastStep + " --> " + o.creationtime
            }
        }
    }
    catch(Exception e){
        println ("Exception occured for process"+ e);
    }}
0
Harisudha On
import de.hybris.platform.core.model.order.OrderModel
import de.hybris.platform.orderprocessing.model.OrderProcessModel


OrderModel orderModel = flexibleSearchService.search(String.format("SELECT {PK} FROM {AbstractOrder} WHERE {code} = '%s'", "P000015003")).result.get(0)

OrderProcessModel orderProcess = new OrderProcessModel();
orderModel.getOrderProcess().forEach {process ->
    if(process.getProcessDefinitionName().contains("global-order-process")){
        businessProcessService.restartProcess(process, "takePaymentAction");   // you can give the node from which you want to start the process
    }
}