Community
Showing results for 
Search instead for 
Do you mean 
Reply

Giving back to the Community - Sample Code - Count Histories, History Types

Copper Super Contributor
Posts: 478
Country: Australia

Giving back to the Community - Sample Code - Count Histories, History Types

Hi all

 

Over the last year i have been writing some code to customise my Act and received a lot of help from the Act Community particularly wellmet, jimdurkin, sam_raikes, vivek, knif and several others. So to help other newbies i will post my code here.

 

Before i do you must understand i am not a coder to claim such would be insulting to those listed above, i only dabble, so my code is not sexy or clean, it is what it is.

 

This was one of my first bits of code, i basically wanted a Time Card system where it would calculate the time i spent on a contacts file doing various tasks which now looks like this in my Contact Layout

Clip.jpg

 

Problems where dealing with the number of History Types including Custom History Types

 

        private void countHistories(string command)
        {
            try
            {
                Act.Framework.Contacts.Contact c = oApp.ApplicationState.CurrentContact;

                if (c != null)
                {
                    // Create count variable
                    int hisCountA = 0;
                    int hisCountB = 0;
                    int hisCountC = 0;
                    int hisCountD = 0;
                    int hisCountE = 0;
                    int hisCountF = 0;
                    int hisCountG = 0;
                    int hisCountH = 0;
                    int hisCountI = 0;

                    // Set inputed user values for history types
                    string typeA1 = "E-mail Sent";
                    string typeA2 = "EmailSent";
                    string typeA3 = "E-mail Attachment";

                    string typeB1 = "FAXSent";
                    string typeB2 = "LeterSent";

                    string typeC1 = "To-do Done";
                    string typeC2 = "ToDoDone";

                    string typeD1 = "Completed VR Other";
                    string typeD2 = "Completed VR Open";
                    string typeD3 = "Completed VR Click";

                    string typeE1 = "Completed Social";

                    string typeF1 = "Call Completed";
                    string typeF2 = "CallCompleted";
                    string typeF3 = "CallReceived";
                    string typeF4 = "CallAttempted";

                    string typeG1 = "Meeting Held";
                    string typeG2 = "MeetingHeld";

                    string typeH1 = "SMS Sent";
                    string typeH2 = "SMS Received";


                    // Date variables and manipulation
                    DateTime today = DateTime.Today;

                    int month = today.Month;
                    int day = today.Day;
                    int year = today.Year;

                    string year1 = c.Fields["CUST_ContactTable1_090144.CUST_ActYear_020643759", true].ToString();

                    DateTime startT = Convert.ToDateTime("01/01/" + year1);
                    DateTime endT = Convert.ToDateTime("31/12/" + year1);

                    List<long> typeADuration = new List<long>();
                    List<long> typeBDuration = new List<long>();
                    List<long> typeCDuration = new List<long>();
                    List<long> typeDDuration = new List<long>();
                    List<long> typeEDuration = new List<long>();
                    List<long> typeFDuration = new List<long>();
                    List<long> typeGDuration = new List<long>();
                    List<long> typeHDuration = new List<long>();
                    List<long> typeIDuration = new List<long>();


                    // Create a list of Histories
                    HistoryList h1 = oApp.ActFramework.Histories.GetHistories(null, c, false);

                    //Cycle through Histories List for each type
                    foreach (History h in h1)
                    {
                        DateTime actualEnd = h.EndTime;

                        // Type A - Emails
                        if ((actualEnd.Date >= startT.Date) && (actualEnd.Date <= endT.Date) && (h.HistoryType.Name == typeA1 || h.HistoryType.Name == typeA2 || h.HistoryType.Name == typeA3))
                        {
                            long duration;
                            duration = h.EndTime.Ticks - h.StartTime.Ticks + 3000000000;

                            typeADuration.Add(duration);

                            hisCountA++;
                        }

                        // Type B - Fax and Letters
                        if ((actualEnd.Date >= startT.Date) && (actualEnd.Date <= endT.Date) && (h.HistoryType.Name == typeB1 || h.HistoryType.Name == typeB2))
                        {
                            long duration;
                            duration = h.EndTime.Ticks - h.StartTime.Ticks;

                            typeBDuration.Add(duration);

                            hisCountB++;
                        }

                        // Type C - ToDos
                        if ((actualEnd.Date >= startT.Date) && (actualEnd.Date <= endT.Date) && (h.HistoryType.Name == typeC1 || h.HistoryType.Name == typeC2))
                        {
                            long duration;
                            duration = h.EndTime.Ticks - h.StartTime.Ticks;

                            typeCDuration.Add(duration);

                            hisCountC++;
                        }

                        // Type D - VR Other
                        if ((actualEnd.Date >= startT.Date) && (actualEnd.Date <= endT.Date) && (h.HistoryType.Name == typeD1))
                        {
                            long duration;
                            duration = h.EndTime.Ticks - h.StartTime.Ticks + 2000000000;

                            typeDDuration.Add(duration);

                            hisCountD++;
                        }

                        // Type I - VR Click and Open
                        if ((actualEnd.Date >= startT.Date) && (actualEnd.Date <= endT.Date) && (h.HistoryType.Name == typeD2 || h.HistoryType.Name == typeD3))
                        {
                            long duration;
                            duration = h.EndTime.Ticks - h.StartTime.Ticks + 2000000000;

                            typeIDuration.Add(duration);

                            hisCountI++;
                        }

                        // Type E - Social Media
                        if ((actualEnd.Date >= startT.Date) && (actualEnd.Date <= endT.Date) && (h.HistoryType.Name == typeE1))
                        {
                            long duration;
                            duration = h.EndTime.Ticks - h.StartTime.Ticks;

                            typeEDuration.Add(duration);

                            hisCountE++;
                        }

                        // Type F - Calls
                        if ((actualEnd.Date >= startT.Date) && (actualEnd.Date <= endT.Date) && (h.HistoryType.Name == typeF1 || h.HistoryType.Name == typeF2 || h.HistoryType.Name == typeF3 || h.HistoryType.Name == typeF4))
                        {
                            long duration;
                            duration = h.EndTime.Ticks - h.StartTime.Ticks;

                            typeFDuration.Add(duration);

                            hisCountF++;
                        }

                        // Type G - Meetings
                        if ((actualEnd.Date >= startT.Date) && (actualEnd.Date <= endT.Date) && (h.HistoryType.Name == typeG1 || h.HistoryType.Name == typeG2))
                        {
                            long duration;
                            duration = h.EndTime.Ticks - h.StartTime.Ticks;

                            typeGDuration.Add(duration);

                            hisCountG++;
                        }

                        // Type H - SMS
                        if ((actualEnd.Date >= startT.Date) && (actualEnd.Date <= endT.Date) && (h.HistoryType.Name == typeH1 || h.HistoryType.Name == typeH2))
                        {
                            long duration;
                            duration = h.EndTime.Ticks - h.StartTime.Ticks + 1000000000;

                            typeHDuration.Add(duration);

                            hisCountH++;
                        }
                    }

                    // Emails and Letters
                    TimeSpan typeATotal;
                    typeATotal = new TimeSpan(typeADuration.Sum());

                    TimeSpan typeBTotal;
                    typeBTotal = new TimeSpan(typeBDuration.Sum());

                    TimeSpan TotalTime1 = typeATotal + typeBTotal;
                    string TotalTime1string = TotalTime1.ToString();

                    int Total1 = hisCountA + hisCountB;
                    string hisCount1 = Total1.ToString();

                    c.Fields["CUST_ContactTable1_090144.CUST_EmailSent_072620355", true] = hisCount1;
                    c.Fields["CUST_ContactTable1_090144.CUST_TimeTotal1_062014473", true] = TotalTime1string;

                    // ToDos
                    TimeSpan typeCTotal;
                    typeCTotal = new TimeSpan(typeCDuration.Sum());

                    string TotalTime2string = typeCTotal.ToString();

                    int Total2 = hisCountC;
                    string hisCount2 = Total2.ToString();

                    c.Fields["CUST_ContactTable1_090144.CUST_ToDoDone_072643224", true] = hisCount2;
                    c.Fields["CUST_ContactTable1_090144.CUST_TimeTotal2_062031113", true] = TotalTime2string;

                    // Calls and Meetings
                    TimeSpan typeFTotal;
                    typeFTotal = new TimeSpan(typeFDuration.Sum());

                    TimeSpan typeGTotal;
                    typeGTotal = new TimeSpan(typeGDuration.Sum());

                    TimeSpan TotalTime3 = typeFTotal + typeGTotal;
                    string TotalTime3string = TotalTime3.ToString();

                    int Total3 = hisCountF + hisCountG;
                    string hisCount3 = Total3.ToString();

                    c.Fields["CUST_ContactTable1_090144.CUST_OtherDone_072655786", true] = hisCount3;
                    c.Fields["CUST_ContactTable1_090144.CUST_TimeTotal3_062040621", true] = TotalTime3string;

                    // SMS
                    TimeSpan typeHTotal;
                    typeHTotal = new TimeSpan(typeHDuration.Sum());

                    string TotalTime4string = typeHTotal.ToString();

                    int Total4 = hisCountH;
                    string hisCount4 = Total4.ToString();
                    c.Fields["CUST_ContactTable1_090144.CUST_SMSTotal_030652598", true] = hisCount4;
                    c.Fields["CUST_ContactTable1_090144.CUST_TimeTotal4_062049885", true] = TotalTime4string;

                    // VR Click and Open
                    TimeSpan typeITotal;
                    typeITotal = new TimeSpan(typeIDuration.Sum());

                    string TotalTime5string = typeITotal.ToString();

                    int Total5 = hisCountI;
                    string hisCount5 = Total5.ToString();
                    c.Fields["CUST_ContactTable1_090144.CUST_VRClickOpen_030759614", true] = hisCount5;
                    c.Fields["CUST_ContactTable1_090144.CUST_TimeTotal5_062058770", true] = TotalTime5string;

                    // VR Other
                    TimeSpan typeDTotal;
                    typeDTotal = new TimeSpan(typeDDuration.Sum());

                    string TotalTime6string = typeDTotal.ToString();

                    int Total6 = hisCountD;
                    string hisCount6 = Total6.ToString();
                    c.Fields["CUST_ContactTable1_090144.CUST_VROther_030841408", true] = hisCount6;
                    c.Fields["CUST_ContactTable1_090144.CUST_TimeTotal6_062108227", true] = TotalTime6string;

                    // Social Media
                    TimeSpan typeETotal;
                    typeETotal = new TimeSpan(typeEDuration.Sum());

                    int Total7 = hisCountE;
                    string hisCount7 = Total7.ToString();
                    c.Fields["CUST_ContactTable1_090144.CUST_Social_093839581", true] = hisCount7;

                    // Grand Total of file time
                    TimeSpan FileTime = typeATotal + typeBTotal + typeCTotal + typeDTotal + typeETotal + typeFTotal + typeGTotal + typeHTotal + typeITotal;
                    string GrantTotalTime = FileTime.ToString();
                    c.Fields["CUST_ContactTable1_090144.CUST_FileTime_061620458", true] = GrantTotalTime;


                    c.Update();

                    //                oApp.RefreshLoadedViews();
                }
                return;
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message, "{0} Exception caught - Count Histories.");
            }

        }

 

 


Jason Dawson Financial Planning
Brisbane | Australia - JDFP Home Page

Act Ver - Act! Premium Version 17.1.169.0, Hot Fix 3
OS - Windows 7 (stand alone machine)
MS Office - Enterprise 2007
Phone - Samsung Galaxy s6
Silver Super Contributor
Posts: 2,328
Country: USA

Re: Giving back to the Community - Sample Code - Count Histories, History Types

Jason,

 

It is very thoughtful and generous of you to post your code to help other developers in the community!

 

Stan


If you would like to get more out of ACT! you can find an ACT! Certified Consultant near you by going to:www.act.com/acc.
-------------------------------------------------------------------------------------
Stan Smith
ACT! Certified Consultant
ADS Programming Services, Inc.
(205) 222-1661
www.adsprogramming.com
www.actwebhosting.com
Click Here to Purchase Act!