Add Z segment to end of message
I am trying to add a custom z-segment to a message. The Below code does not error out but I also do not get the segment added. Any assistance would be greatly appreciated.
Class CDSM.AddFedExID.AddFedExIDProcess Extends Ens.BusinessProcess [ ClassType = persistent, Language = objectscript ]
{
/// Add "Business Process" or "Business Operation" for the target
Property TargetConfigName As %String;Parameter SETTINGS As %String = "TargetConfigName:Additional";
Method OnRequest(pRequest As EnsLib.HL7.Message, Output pResponse As Ens.Response) As %Status
{
#dim newrequest = pRequest.%ConstructClone()
#dim eException As %Exception.AbstractException
#dim tSC As %Status =$$$OK
set FedExID = "123456"
set segcount = newrequest.SegCountGet()
$$$LOGINFO("segcount "_segcount)
set newsegpos = segcount +1
$$$LOGINFO("newsegpos "_newsegpos)
set zm1str = "ZM1|1|"
set zm1 = ##class(EnsLib.HL7.Segment).ImportFromString(zm1str,.sc,pRequest.Separators)
set newseg = newrequest.setSegmentByIndex(zm1,newsegpos)SET pRequest = newrequest
#;SET tSC = ..SendRequestSync("HL7FileOperation", newrequest)
SET tSC = ..SendRequestSync(..TargetConfigName, newrequest)
#;return newrequestQuit tSC
}
Comments
Hi Rick,
Maybe no fatal errors, but you should check the status codes in case they contain one. Couple of (untested) change suggestions below to try first...
$$$QuitOnError(sc)
set newseg = newrequest.setSegmentByIndex(zm1,newsegpos) SET pRequest = newrequest
$$$QuitOnError(newseg)
Thanks Sean! I was able to trouble shoot and came up with the below code that does add my ZM1 segment.
Method OnRequest(pRequest As EnsLib.HL7.Message, Output pResponse As Ens.Response) As %Status
{
#dim newrequest = pRequest.%ConstructClone()
#dim eException As %Exception.AbstractException
#dim tSC As %Status =$$$OK
SET FedExID = "123456"
SET segcount = newrequest.SegCountGet()
$$$LOGINFO("segcount "_segcount)
SET newsegpos = segcount +1
$$$LOGINFO("newsegpos "_newsegpos)
SET zm1str = "ZM1|1|||||||||||||||||||" _FedExID
#;SET zm1str = "ZM1|1|||||||||||||||||||" _FedExID _"|"
SET zm1 = ##class(EnsLib.HL7.Segment).ImportFromString(zm1str,.sc,pRequest.Separators)
$$$QuitOnError(sc)
SET newseg = newrequest.SetSegmentAt(zm1,newsegpos)
$$$QuitOnError(newseg)
SET pRequest = newrequest
#;SET tSC = ..SendRequestSync("HL7FileOperation", newrequest)
SET tSC = ..SendRequestSync(..TargetConfigName, newrequest)
#;return newrequestQuit tSC
}