Community
Showing results for 
Search instead for 
Do you mean 
Reply

Giving back to the Community - Sample Code - Buttons and Activities

Copper Super Contributor
Posts: 478
Country: Australia

Giving back to the Community - Sample Code - Buttons and Activities

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.

 

My first bit of code was to create and automate workflow in fact thats what most of my code does in some way, so a button was created for mail received from a contact it created a Note and Activities (more recently i added a DropBox folder checker but that code will come later), this button was then duplicated so now i have 5 for different events relevant to a contact and the business i do

 

 

    [Act.Shared.ComponentModel.CustomControl(true)]

    //Document inwards Button
    class DocumentsInButton : System.Windows.Forms.Button
    {
        protected override void OnClick(System.EventArgs e)
        {
            try
            {

                Contact c = Act.UI.ActApplication.Instance.ApplicationState.CurrentContact;

                //List out the activity types
                Act.Framework.Activities.ActivityType[] activityTypes = Act.UI.ActApplication.Instance.ActFramework.Activities.GetActivityTypes();

                //List out the note types
                Act.Framework.Notes.NoteType[] noteTypes = Act.UI.ActApplication.Instance.ActFramework.Notes.GetNoteTypes();

                //set a new activity template link
                Act.Framework.Activities.ActivityTemplate aTemplate;

                foreach (Act.Framework.Activities.ActivityType a in activityTypes)
                {
                    if (a.Name == "To-do")
                    {
                        string regarding = "Document has been received regarding (" + c.FullName + ")";
                        string details = "Document has been received\n\nRegarding: Refer Note\n\n\n(If additional activities are required as a result of the document a new activity needs to be created for each issue)";
                        string location = "Office";

                        aTemplate = Act.UI.ActApplication.Instance.ActFramework.Activities.CreateActivity(a);
                        aTemplate.ActivityContacts.Add(c);
                        aTemplate.StartTime = System.DateTime.Now;
                        aTemplate.EndTime = System.DateTime.Now.AddMinutes(2);
                        aTemplate.Regarding = regarding;
                        aTemplate.Location = location;
                        aTemplate.Details = details;
                        aTemplate.Priority = Act.UI.ActApplication.Instance.ActFramework.Activities.GetActivityPriority("Low");
                        aTemplate.Update();
                    }
                    if (a.Name == "To-do")
                    {
                        string regarding = "Review recently received document regarding (" + c.FullName + ")";
                        string details = "Review the document and establish what if anything needs to be done\n\n(If additional activities are required as a result of the document a new activity needs to be created for each issue)";
                        string location = "Office";

                        aTemplate = Act.UI.ActApplication.Instance.ActFramework.Activities.CreateActivity(a);
                        aTemplate.ActivityContacts.Add(c);
                        aTemplate.StartTime = System.DateTime.Now.AddHours(2);
                        aTemplate.EndTime = aTemplate.StartTime.AddMinutes(15);
                        aTemplate.Regarding = regarding;
                        aTemplate.Location = location;
                        aTemplate.Details = details;
                        aTemplate.Priority = Act.UI.ActApplication.Instance.ActFramework.Activities.GetActivityPriority("Medium");
                        aTemplate.Update();
                    }
                }

                DateTime now = DateTime.Now;

                //Set a new Note
                Act.UI.ActApplication.Instance.ActFramework.Notes.CreateNote(noteTypes[0], "Document Recieved\nThis is a document related to " + c.FullName + "\n\n\nSource of Document:\n\nDetails:\n\nAlterations Required: Yes / No\n\nCost Incured:\n(If relevant)\n\nLost of Benefit:\n(If relevant)\n\nAction Required:\n\n", now, false, c);

                // Folder Checking Method
                // Checks and creates missing folders based on the client type group

                //Get current contact group
                string ContactRecordType = c.Fields["TBL_CONTACT.INSTANTMSGID", true].ToString();
                var instance = new DropBoxFolderCheker();
                instance.cSort(ContactRecordType, null);

                c.Update();

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message, "{0} Exception caught - Doc Inward Button");
            }

        }
    }

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