Question
Kurro Lopez · Sep 19, 2017

Create a task and call to a Business Process [SOLVED]

Hi all,

I wonder if is possible to create a task object and this task calls to a Business Process (or business operation)

My attempt was:

/// Task Special purge 
Class MyTasks.SpecialPurge Extends %SYS.Task.Definition
{
   Parameter PROPERTYVALIDATION = 1;
   Parameter BPSPECIALPURGE= "Special Purge";
   Parameter TaskName = "Special purge in SQL";

   Property MinutesDelay As %Integer [ InitialExpression = 15, Required ];

   Method OnTask() As %Status
   {
       // Create the date to purge
       set datePurge= $SYSTEM.SQL.DATEADD("minute",-1*..MinutesDelay, $HOROLOG)

      $$$ThrowOnError(##class(Ens.Director).CreateBusinessService(..#BPSPECIALPURGE, .tService))
      If ($IsObject(tService)) {
        Set tSC = tService.ProcessInput(datePurge,.output)
      }
   }

}

But it doesn't work.

Other attempt was extend the class to Ens.BusinessService to call directly using the method

set tSC = ..SendRequestSync(..#BPSPECIALPURGE, datePurge, .pOutput)

But this idea also doesn't work

Any idea how to do?

Best regards

0
0 1,294
Discussion (5)2
Log in or sign up to continue

I wonder why this is not working as i have called the service many times through custom tasks that i create.

You could, may be, put the code inside a Try/Catch to see what's the real problem.

Sample code from one of my tasks...

Class DisenrollMemberTask Extends %SYS.Task.Definition
{

Property MemberDisenrollService As %String [ InitialExpression = "MemberDisenrollService " ];

Method OnTask() As %Status
{
  Set tStatus=$System.Status.OK()
  Try {
    #Dim tMemberDisenrollService  As CUSTOM.Demo.Task.Service.DisenrollMember

    Set tStatus=##class(Ens.Director).CreateBusinessService(..MemberDisenrollService , .tMemberDisenrollService  )
    If ($System.Status.IsError(tStatus)){
       $$$ThrowOnError(tStatus)
    }

    If ($Isobject(tMemberDisenrollService)) {
       Set tStatus=tMemberDisenrollService.DisenrollMember("xyz", "abc")

       If ($System.Status.IsError(tStatus)){
          $$$ThrowOnError(tStatus)
       }
    }
  } Catch (ex){
    Set tStatus=ex.AsStatus()
  }

  Quit tStatus
}

}

Thanks for the solution.

The problem was that I should to call to a BS, not a BP instead. So I've created a dummy BS to call the BP to do the process.

 

Thanks again for the key

I see.. you need to may be declare the service class ...

#Dim tService As Service.class

Check out Demo.ZenService.Zen.WeatherReportForm class in ENSDEMO namespace. GetWeatherReport method there creates a BS and sends a message to a BP outside of Ensemble context. You need to send an object and not a datatype, so in your example:

Set tSC = tService.ProcessInput(datePurge,.output)

Should be instead:

Set message = ##class(Ens.StringContainer).%New(datePurge)
Set tSC = tService.ProcessInput(message,.output)

If you want to send a message to a BP or BO you can do that too, just create an Ensemble message and use SendSync or SendAsync to send it from BS:

Set message = ##class(Ens.StringContainer).%New(datePurge)
Set targetHostName = "Name of BP or BO"
Set description = "My request description"
// Set timeout = 10 // how long to wait for a Sync call response, skip to wait forever
// Set tSC = tService.SendRequestSync(targetHostName, message, .response, timeout, description)
Set tSC = tService.SendRequestAsync(targetHostName, message, description)

That said, Ensemble hosts can run on schedule so you can use built-in Ensemble scheduler and not a system task manager.