Question
Scott Roth · Feb 23

Sending request data to Business Object through Object Script

So now that I have figured out how to send a Page via HTTP.OutboundAdapter, I have another question. I want to use a Function that all I have to do is pass two variables and it is sent to the HTTP.OutboundAdapter I created to send the Page. 

So.. If I have a class file that Extends Ens.Rule.FunctionSet, how do I force it to send a Request to my HTTP Business Operation, without having to go through a DTL, or Business Process?

 

Thanks

Scott

00
2 0 3 109
Log in or sign up to continue

Hey Scott.

If you were open to having a Service in your production which is what your function sends its two variables (and the service then passes it onto your Operation) you could have something like this:

ClassMethod SendPage(PagerNumber As %String, Message As %String) As %Status
{
    //The String passed to Ens.Director must match a service name within the active production
    set tsc = ##class(Ens.Director).CreateBusinessService("Pager From Function Service",.tService)
    
    if ($IsObject(tService))
    {
        set input = ##class(osuwmc.Page.DataStructures.Page).%New()
        set input.PagerNumber = PagerNumber
        Set input.Message = Message
        
        set tsc = tService.ProcessInput(input)
        Quit tsc
                
    }
    else
    { 
    Quit 0
    }
}

and then you have a custom service that looks a little like this:

Class osuwmc.Services.PageService Extends Ens.BusinessService
{
Property TargetConfigName As Ens.DataType.ConfigName;

Parameter SETTINGS = "TargetConfigName";

Method OnProcessInput(pRequest As osuwmc.Page.DataStructures.Page) As %Status
{
    set tsc=..SendRequestAsync(..TargetConfigName, pRequest)
    
    Quit tsc
}

}

Then when you add the service to your production (remembering to match it to the name declared in the service code), you can select your target operation as a config item, and when the function is triggered it should go Function -->Service-->Operation.

Edit: my Service Class example had an error in the SETTINGS parameter, I have corrected it. 

Quick example:

Class Demo.FunctionSet Extends Ens.Util.FunctionSet
{

ClassMethod SendRequestToHTTPOp(arg1 as %String, arg2 as %String) as %String {
    if '$D(%Ensemble("%Process")) {
        write "This doesn't work in DTL test mode",!
        quit "OOPS"
    } else {
        #dim bp as Ens.BusinessProcess

        set req = ##class(Ens.StringRequest).%New()
        
        set req.StringValue=arg1_"^"_arg2

        set bp=%Ensemble("%Process")
        set tSC=bp.SendRequestSync("My.HTTP.Operation",req,.resp)
        
        if $$$ISERR(tSC) {
            // Oops... error!
        }
        
        quit "SEND SOMETHING BACK TO WHATEVER CALLED US"
    }
}

}