'How to repair a business process in hybris using groovy?
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
}
}
Solution 1:[1]
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);
}}
Solution 2:[2]
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
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Raushan Kumar |
Solution 2 | Harisudha |