Question
· Sep 20, 2022

CreateBusinessService() from Trigger

I'm trying to send a message into a production on change a persistent object. 

And when I change an object using SQL - I get an error, 
when change the object using objectscript - I get  a message (but not an error or exception) 
But the most interesting - everything works fine (the object has been changed, and business service receives data) 

Persistent class

Class Demo.Person Extends %Persistent
{
Property Name As %String;
Property Status As %Integer;
Trigger UpdateTrigger [ Event = UPDATE, Foreach = row/object, Time = AFTER ]
{
    if ( ({Status*O}=0)&&({Status*N}=1) ) {
        do ##class(Demo.Person).SendToProduction({Name})
    }
}
ClassMethod SendToProduction(name As %String) As %Status
{
    set sc = ##class(Ens.Director).CreateBusinessService("DemoService", .service)
    return:$$$ISERR(sc) sc
    set sc = service.ProcessInput(##class(Ens.StringContainer).%New(name))
    return sc
}
}

Business Service

 
Spoiler

Production

 
Spoiler

SQL Query

UPDATE Demo.Person
SET Status = 1
WHERE ID = 1

An error executing this query

  [SQLCODE: <-400>:<Fatal error occurred>]
  [%msg: <Unexpected error occurred: <COMMAND>%0Ac+1^%sqlcq.TEST.cls3.1 *NoTransaction>]

In terminal

TEST>set pers = ##class(Demo.Person).%OpenId(1)

TEST>write pers.Status  
0
TEST>set pers.Status = 1
TEST>set sc = pers.%Save()

07:02:44.836:Demo.DemoService: aaa
07:02:44.840:Demo.DemoService: 1 open user transaction found after OnProcessInput(); committing before proceeding
TEST>write sc
1

1. Why I see these messages?

"07:02:44.836:Demo.DemoService: aaa" - it's a $$$TRACE from BusinessService
"07:02:44.840:Demo.DemoService: 1 open user transaction found after OnProcessInput(); committing before proceeding" - It's a warning in Production Log.

2. How to work correctly with Interoperability from Triggers?

Now, I use job command from trigger, as a workaround 

job ##class(Demo.Person).SendToProduction({Name})
Product version: IRIS 2022.1
$ZV: IRIS for UNIX (Ubuntu Server LTS for ARM64 Containers) 2022.1 (Build 209U) Tue May 31 2022 12:14:00 EDT
Discussion (2)1
Log in or sign up to continue