There are DSL-style interfaces available through the ServiceFacade (ec.getService(), or in Groovy ec.service) that have options applicable to the various ways of calling a service. All of these service call interfaces have name() methods to specify the service name, and parameter() and parameters() methods to specify the input parameters for the service. These and other methods on the various interfaces return an instance of themselves so that calls can be chained. Most have some variation of a call() method to actually call the service.
Map ahp = [visitId:ec.user.visitId, artifactType:artifactType, ...] ec.service.async().name("create", "moqui.server.ArtifactHit").parameters(ahp).call() Map result = ec.service.sync().name("org.moqui.impl.UserServices.create#UserAccount").parameters(params).call()
The first service call is to an implicitly defined entity CrUD service to create a ArtifactHit record asynchronously. Note that for async() the call() method returns nothing and in this case the service call results are ignored. The second is a synchronous call to a defined service with a params input parameter Map, and because it is a sync() call the call() method returns a Map with the results of the service call.
Beyond these basic methods each interface for different ways of calling a service has methods for applicable options, including:
sync(): Call the service synchronously and return the results.
async(): Call the service asynchronously and ignore the results, get back a ServiceResultWaiter object to wait for the results, or pass in an implementation of the ServiceResultReceiver interface to receive the results when the service is complete.
java.util.concurrent.Futureinstance used to wait for and receive the service results.
special(): Register the current service to be called when the current transaction is either committed (use registerOnCommit()) or rolled back (use registerOnRollback()). This interface does not have a call() method.
moqui.service.job.ServiceJobParameterentities. Here is an example of a schedule job from MoquiInstallData.xml file, which is in place by default in Moqui
<moqui.service.job.ServiceJob jobName="clean_ArtifactData_daily" description="Clean Artifact Data: ArtifactHit, ArtifactHitBin" serviceName="org.moqui.impl.ServerServices.clean#ArtifactData" cronExpression="0 0 2 * * ?" paused="N"> <parameters parameterName="daysToKeep" parameterValue="90"/> </moqui.service.job.ServiceJob>