3 Replies - 1224 Views - Last Post: 26 August 2014 - 11:26 AM Rate Topic: -----

#1 winkimjr2   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 148
  • Joined: 30-May 12

How do I check if a value exist before adding it to avoid duplicates?

Posted 26 August 2014 - 10:49 AM

Can someone please help me with this. I have pasted my Visual Basic.Net code here. What I want to do is add a code in the section with a comment 'Process other identification.
In this section, the code adds the NCIC number (ProtectionOrderOtherIdentificationTypeCode). So before adding, I Want to first check if NCIC Number (ProtectionOrderOtherIdentificationTypeCode) already exists. If it exists, I do not want to add the same number twice so outstanding failure should be raised. However I want to be able to add more than one NCIS number as long as these NCIS numbers are not duplicated.
I would like the error(exception) text should say something like this:
Protection Order[PO number goes here] already has NCIC number[NCIC number from MNCIS].

Example of exception message:

Protection Order 1400456 already has NCIC number 87654321 associated with it..

How do I accomplish this? I am sure it is simple but I am not able to figure it out. Someone help.

Visual Studio 2010 Code
Protected Overrides Sub ProcessMessage(ByRef aobjBroker As MessageBroker.Library.v4.Broker, ByRef aobjXmlInputDoc As System.Xml.XmlDocument, ByRef aobjInstantiatedObjectsCollection As Microsoft.VisualBasic.Collection)
            MyBase.ProcessMessage(aobjBroker, aobjXmlInputDoc, aobjInstantiatedObjectsCollection)

            Dim strCaseNumber As String
            Dim strProtectionOrderNumber As String
            Dim objNameTable As NameTable
            Dim objXMLNameSpaceManager As XmlNamespaceManager
            Dim objXmlServiceNode As XmlNode
            Dim objProtectionOrder As Msc.Integration.Mncis.Library.v4.ProtectionOrder
            Dim objXmlCrossReferenceNode As XmlNode
            'create a namespace manager used for queries into inputmessage (because of namespace)
            objNameTable = New NameTable
            objXMLNameSpaceManager = New XmlNamespaceManager(objNameTable)
            objXMLNameSpaceManager.AddNamespace("ext", "http://www.courts.state.mn.us/ProtectionOrderExtension/1.0")
            objXMLNameSpaceManager.AddNamespace("nc", "http://niem.gov/niem/niem-core/2.0")


            strCaseNumber = aobjXmlInputDoc.DocumentElement.SelectSingleNode("ext:CourtFileNumber", objXMLNameSpaceManager).InnerText
            strProtectionOrderNumber = aobjXmlInputDoc.DocumentElement.SelectSingleNode("ext:ProtectionOrderID", objXMLNameSpaceManager).InnerText
            objProtectionOrder = Msc.Integration.Mncis.Library.v4.ProtectionOrder.Get(strCaseNumber, CInt(strProtectionOrderNumber), False)


            'Process service 
            For Each objXmlServiceNode In aobjXmlInputDoc.DocumentElement.SelectNodes("ext:ProtectionOrderService", objXMLNameSpaceManager)

            Next





            'Process other identification
            objXmlCrossReferenceNode = aobjXmlInputDoc.DocumentElement.SelectSingleNode("ext:ProtectionOrderOtherIdentification", objXMLNameSpaceManager)

            If Not objXmlCrossReferenceNode Is Nothing Then
                'objProtectionOrder.AddCrossReferenceNumber(objXmlCrossReferenceNode.SelectSingleNode("ext:ProtectionOrderOtherIdentificationTypeCode", objXMLNameSpaceManager).InnerText, objXmlCrossReferenceNode.SelectSingleNode("nc:IdentificationID", objXMLNameSpaceManager).InnerText)
                objProtectionOrder.AddCrossReferenceNumber(objXmlCrossReferenceNode.SelectSingleNode("nc:IdentificationID", objXMLNameSpaceManager).InnerText, objXmlCrossReferenceNode.SelectSingleNode("ext:ProtectionOrderOtherIdentificationTypeCode", objXMLNameSpaceManager).InnerText)
            End If






            'Save updates
            Msc.Integration.Mncis.Library.v4.Odyssey.SaveUpdates(CType(objProtectionOrder, Msc.Integration.Mncis.Library.v4.IApiObject))


        End Sub


Is This A Good Question/Topic? 0
  • +

Replies To: How do I check if a value exist before adding it to avoid duplicates?

#2 Xaos   User is offline

  • D.I.C Regular

Reputation: 80
  • View blog
  • Posts: 403
  • Joined: 20-November 13

Re: How do I check if a value exist before adding it to avoid duplicates?

Posted 26 August 2014 - 11:08 AM

I don't know VB.Net syntax, but generally in this situation you'd get your NCIC number, loop through and check if that number currently exists, and if it doesn't, add it. For each.....if (object == NCIC number) don't add. If reach end of loop and no numbers matched, add.


And then in your loop, after a match is found, exit loop and give exception message.

This post has been edited by Xaos: 26 August 2014 - 11:08 AM

Was This Post Helpful? 0
  • +
  • -

#3 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14761
  • View blog
  • Posts: 59,004
  • Joined: 12-June 08

Re: How do I check if a value exist before adding it to avoid duplicates?

Posted 26 August 2014 - 11:11 AM

I would start by putting all the items into a searchable collection up front.. that makes reviewing what is there/is not there a relatively easy task.


I always say - if you don't like the structure given - make your own!
Was This Post Helpful? 0
  • +
  • -

#4 winkimjr2   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 148
  • Joined: 30-May 12

Re: How do I check if a value exist before adding it to avoid duplicates?

Posted 26 August 2014 - 11:26 AM

View PostXaos, on 26 August 2014 - 11:08 AM, said:

I don't know VB.Net syntax, but generally in this situation you'd get your NCIC number, loop through and check if that number currently exists, and if it doesn't, add it. For each.....if (object == NCIC number) don't add. If reach end of loop and no numbers matched, add.


And then in your loop, after a match is found, exit loop and give exception message.

I think you TOTALLY understood what I need to do. I like what you suggested the only problem is that I am stuck on how to do the For Each loop. Could you please give me a little more guidance?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1