1

This seems like an easy question, but I cannot find an answer to it and I am just not seeing it myself. I have a straightforward set of SysOperation classes, contract/service/controller. However, I'm reusing this batch job in other places in the system that are highly automated processes. I want to be able to call this batch job asynchronously, no dialog, and with a contract built from certain results/data during the automated process.

Question: How do I pass in a contract to the controller class when the entire process is automated? I won't be able to show the dialog that would usually be create the contract to be magically passed to the controller when user interaction is involved.

I would call the service code directly and pass in the contract that way, but I want the logging that comes with the batch job so that runs can be seen in the SysAdmin module and it seems that is all built within the controller class. Perhaps this is not possible?

rjv
  • 1,058
  • 11
  • 29

1 Answers1

3

Is this what you're asking for? I'm not entirely sure I understand the question.

If you're doing things in batch, you may need to create a batch header and add tasks.

// These are two random controller/contract classes...this has not been tested
AssetTransferMassController     controller  = AssetTransferMassController::construct(); // Define controller
AssetTransferMassContract       contract    = controller ? controller.getDataContractObject() : null; // Define contract

if (!contract)
    throw error(Error::wrongUseOfFunction(funcName()));

// Set contract fields
contract.parmTransferDate(systemDateGet());
// etc: contract.parm[...]
// etc: contract.parm[...]

controller.parmExecutionMode(SysOperationExecutionMode::Asynchronous); // Set execution mode
controller.parmShowDialog(false); // Prevent dialog
controller.parmLoadFromSysLastValue(false); // Prevent loading from last value

// Start operation
controller.startOperation();    

info("Done");
Alex Kwitny
  • 11,211
  • 2
  • 49
  • 71
  • This was it. I didn't realize the controller had already instantiated the contract (and determined the type through what I imagine to be reflection of the service method's contract parameter). – rjv Mar 17 '20 at 21:09
  • @rjv glad I could help. Yes the key here is `controller.getDataContractObject();` – Alex Kwitny Mar 17 '20 at 23:08