Community
Showing results for 
Search instead for 
Do you mean 
Reply

Get Contact using Lastname, firstname as filter criteria

Copper Contributor
Posts: 11
Country: USA

Get Contact using Lastname, firstname as filter criteria

Dear All Helpers,
I am fairly new to .net and Act framework. I cannot find the syntax for doing a search for a contact based on lastname and firstname. I am adding a new contact in program and I want to do a lookup to see if there is already someone with that first and last name. Then I want to display their name and address and one or two specific fields so the user can determine if this is a duplicate or another different contact altogether.
I have searched the Act 9 and act 2008 sdk help but nothing quite fits the need.
Any help would be much appreciated.
Thanks.
John
Copper Contributor
Posts: 11
Country: USA

Re: Get Contact using Lastname, firstname as filter criteria

I forgot.. I am using vb.net. John
Copper Contributor
Posts: 98
Country: United States

Re: Get Contact using Lastname, firstname as filter criteria

Hey John,
 
I've replied via email as well... but here is a VB.NET version of the answer I sent earlier
NOTE: This was converted to VB though a VB to C# utility to I make no promises about its functionality unmodified.
 
    Private Sub btnPopulate_Click(ByVal sender As ObjectByVal As EventArgs)
        
'Save Current Changes
        
Dim cContact As Contact ActApp.ApplicationState.CurrentContact
        cContact.Update

        'Perform Lookup
        
Dim cColumn3 As CriteriaColumn
        
Dim cColumn1 As CriteriaColumn
        
Dim cColumn2 As CriteriaColumn
        
Dim oOperator1 As OperatorEnum
        
Dim sValue3 As String
        Dim 
sValue1 As String
        Dim 
sValue2 As String
        Dim 
cLookup As ContactLookup
        
Dim cList As ContactList

        
'initialize some varables
        
oOperator1 OperatorEnum.EqualTo
 
        'Cust ID
        sValue1 txtCustomerID.Text.ToString
        
'Company Name
        
sValue2 txtCustomerName.Text.ToString
        'Phone Number

        
sValue3 txtPhone.Text.ToString

        'Get the column(s) to lookup on
        
cColumn1 ActFwk.Lookups.GetCriteriaColumn("TBL_CONTACT""USER10"true)
        cColumn2 
ActFwk.Lookups.GetCriteriaColumn("TBL_CONTACT""COMPANYNAME"true)
        cColumn3 
ActFwk.Lookups.GetCriteriaColumn("TBL_ADDRESS""LINE1"true)

        'Create an array to hold all of the lookup criteria
        
Dim lCriteria() As Criteria = New Criteria() {New Criteria(LogicalOperator.OrCType(0,Byte), CType(0,Byte), cColumn1, oOperator1, sValue1), New Criteria(LogicalOperator.OrCType(0,Byte), CType(0,Byte), cColumn1, oOperator1, sValue2), New Criteria(LogicalOperator.EndCType(0,Byte), CType(0,Byte), cColumn1, oOperator1, sValue3)}

        'Create the Lookup 
        
cLookup ActFwk.Lookups.LookupContactsReplace(lCriteria, truetrue)

        'Set our contact list to the lookup
        
cList cLookup.GetContacts(Nothing)
        ActApp.ApplicationState.SetCurrentContactList(cList, Nothing)
        ActApp.UIContactManager.ShowDetailView

        
'If contact does not already exist in the database
        
If (cList.Count 0Then
        '......... etc.......
Carlton Jones
Sage Software
Copper Contributor
Posts: 98
Country: United States

Re: Get Contact using Lastname, firstname as filter criteria

Per Request C# version:    
 

        private void btnPopulate_Click(object sender, EventArgs e)

        {

            //Save Current Changes

            Contact cContact = ActApp.ApplicationState.CurrentContact;

            cContact.Update();

 

            //Perform Lookup

            CriteriaColumn cColumn1, cColumn2, cColumn3;

            OperatorEnum oOperator1;

            string sValue1, sValue2, sValue3;

            ContactLookup cLookup;

            ContactList cList;

            //initialize some varables

            oOperator1 = OperatorEnum.EqualTo;

            sValue1 = txtCustomerID.Text.ToString(); //Scopus ID

            sValue2 = txtCustomerName.Text.ToString(); //Company

            sValue3 = txtPhone.Text.ToString(); //Phone Number

 

            //Get the column(s) to lookup on

            cColumn1 = ActFwk.Lookups.GetCriteriaColumn("TBL_CONTACT", "USER10", true);

            cColumn2 = ActFwk.Lookups.GetCriteriaColumn("TBL_CONTACT", "COMPANYNAME", true);

            cColumn3 = ActFwk.Lookups.GetCriteriaColumn("TBL_ADDRESS", "LINE1", true);

 

            //Create an array to hold all of the lookup criteria

            Criteria[] lCriteria = new Criteria[] {new Criteria(LogicalOperator.Or, (byte)0, (byte)0, cColumn1, oOperator1, sValue1),

                                       new Criteria(LogicalOperator.Or, (byte)0, (byte)0, cColumn1, oOperator1, sValue2),

                                       new Criteria(LogicalOperator.End, (byte)0, (byte)0, cColumn1, oOperator1, sValue3)

                                      };

            //Create the Lookup

            cLookup = ActFwk.Lookups.LookupContactsReplace(lCriteria, true, true);

            //Set our contact list to the lookup

            cList = cLookup.GetContacts(null);

            ActApp.ApplicationState.SetCurrentContactList(cList, null);

            ActApp.UIContactManager.ShowDetailView();

 

            //If contact does not already exist in the database

            if (cList.Count == 0)

            {

               //....etc....

Carlton Jones
Sage Software