Using Lists and ListFind within BPL
I already mentioned in a Previous post I am trying to build a list from a repeatable field within a HL7 message. I figured out how to build the list by using a context list string variable within the Business Process (BPL) and doing a
do context.<variable>.Insert = <value>when I am looping through the field. I want to do it one step farther though... I want to search the list to see if the value exists before I do the insert. I only want to insert if the value is different than what is in the list already.
IF$LF(context.Facilities,##class(Ens.Rule.FunctionSet).SubString(context.EpicDepartmentID,1,4)) = 0
{
do context.Facilities.Insert = ##class(Ens.Rule.FunctionSet).SubString(context.EpicDepartmentID,1,4)
}I tried using $LF or $LISTFIND, but I keep getting the same error...
ERROR <Ens>ErrBPTerminated: Terminating BP EpicMFNToCPD # due to error: ERROR <Ens>ErrException: <LIST>S36+3 ^osuwmc.Epic.MFN.EpicMFNToCPD.Thread1.1 -- logged as '-'
number - @'
IF $LF(context.Facilities,##class(Ens.Rule.FunctionSet).SubString(context.EpicDepartmentID,1,4)) = 0'
> ERROR <Ens>ErrException: <LIST>S36+3 ^osuwmc.Epic.MFN.EpicMFNToCPD.Thread1.1 -- logged as '-'
number - @'
IF $LF(context.Facilities,##class(Ens.Rule.FunctionSet).SubString(context.EpicDepartmentID,1,4)) = 0'
Any guidance would be appreciated.
Comments
I think you just confusing $listbuild with list in BPL context. In BPL when you define it as List Collection, it will use class %Collection.ListOfDT, or in case of array it will be %Collection.ArrayOfDT
That means, that you should use
if 'context.Facilities.Find(##class(Ens.Rule.FunctionSet).SubString(context.EpicDepartmentID,1,4))
{
do context.Facilities.Insert(##class(Ens.Rule.FunctionSet).SubString(context.EpicDepartmentID,1,4))
}