Community
Showing results for 
Search instead for 
Do you mean 
Reply

Error in Button Code

Copper Super Contributor
Posts: 478
Country: Australia

Error in Button Code

Hi all

 

I am writing a button code for the contact view screen, the aim is for the button to create a set of 10+ activities of a specific set of events

 

However i cant get the code working, the button shows up all good but when i click on it i get "Object reference not set to an instance of an object" message dialog box

 

There is no red errors in VS so i am not certain what the problem is

 

Any help?

 

namespace JDFPButton1
{
    [Act.Shared.ComponentModel.CustomControl(true)]

    class Button1 : System.Windows.Forms.Button
    {
        //Set ACT Application Object
        internal ActApplication oApp;

        protected override void OnClick(System.EventArgs e)
        {
            //  Contact c = oApp.ApplicationState.CurrentContact;
            Act.Framework.Contacts.Contact c = oApp.ApplicationState.CurrentContact;
                
            //Your code here, you can access the current contact via:

            Array activityTypes = oApp.ActFramework.Activities.GetActivityTypes();
            Act.Framework.Activities.ActivityTemplate aTemplate;

            string regarding = "";

            foreach (Act.Framework.Activities.ActivityType a in activityTypes)
            {
                if (a.Name == "To-Do")
                {
                    aTemplate = oApp.ActFramework.Activities.CreateActivity(a);
                    aTemplate.ActivityContacts.Add(c);
                    aTemplate.StartTime = System.DateTime.Now;
                    aTemplate.EndTime = System.DateTime.Now;
                    aTemplate.Regarding = regarding;
                    aTemplate.Update();
                }
            }

                c.Update();

                oApp.RefreshLoadedViews();
        }
    }
    
}

 


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: Error in Button Code

Arrays aren't a collection so you can't enumerate them using a for...each.

 

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!
Copper Super Contributor
Posts: 478
Country: Australia

Re: Error in Button Code

hmm got that bit of code from an Act Moderator....

So basically what your saying is the code tries to go through the list but there is actually nothing there

Great

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
Nickel Contributor
Posts: 175
Country: USA

Re: Error in Button Code

[ Edited ]

It looks like you declared the array incorrectly. You are actually creating an Array object, not an array of ActivityTypes. There's a difference and that is probably why you are having issues with the foreach loop.

 

//This is an incorrect declaration for your inteded use 
Array activityTypes = oApp.ActFramework.Activities.GetActivityTypes();

//Use this instead
 Act.Framework.Activities.ActivityType[] activityTypes = oApp.ActFramework.Activities.GetActivityTypes();

 

Edit: On a site note, I've used a for...each on arrays a lot in VB.NET. If I recall correctly, you can use a for...each on anything that implements the IEnumeration or IEnumerable interfaces, which arrays do.

Copper Super Contributor
Posts: 478
Country: Australia

Re: Error in Button Code

Ok thanks i will try that

One question, if i want to do several buttons do i need to do a different .dll or can i duplicate the code in the same file?

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
Copper Super Contributor
Posts: 478
Country: Australia

Re: Error in Button Code

it still does not work

have i got the "internal ActApplication oApp;" correct?

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
Copper Super Contributor
Posts: 478
Country: Australia

Re: Error in Button Code

Ok i do have a warning pop up

"Warning 1 Field 'JDFPButton1.Button1.oApp' is never assigned to, and will always have its default value null d:\users\jason\documents\visual studio 2013\Projects\JDFPButton1\JDFPButton1\Class1.cs 29 33 JDFPButton1
"

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
Copper Super Contributor
Posts: 478
Country: Australia

Re: Error in Button Code

It works now, i did it long hand ...yippy

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
Copper Contributor
Posts: 42
Country: Germany

Re: Error in Button Code

could you please be so kind and tell us, what was the solution, or repost your correct code.

 

you can put multiple "customcontrols" into a single .dll-file.

Copper Super Contributor
Posts: 478
Country: Australia

Re: Error in Button Code

This is the whole code for one of the buttons i use

 

Note: most of the "using" are not required

and

the long hand was                     aTemplate = Act.UI.ActApplication.Instance.ActFramework.Activities.CreateActivity(a);

 

I could not work out how to put more than one button in the same dll so i now have 3 dll's and i could not work out how to make recuring activities

 

using System;
using System.Windows.Forms;
using System.ComponentModel;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Act.UI;
using Act.Shared.Collections;
using Act.Framework;
using Act.UI.Core;
using Act.Framework.Contacts;
using Act.Framework.Histories;
using Act.Framework.Notes;
using Act.Framework.ComponentModel;
using Act.Framework.CustomEntities;
using Act.Framework.MutableEntities;


namespace JDFPButton1
{
    [Act.Shared.ComponentModel.CustomControl(true)]

    class Button1 : System.Windows.Forms.Button
    {
        protected override void OnClick(System.EventArgs e)
        {
            Contact c = Act.UI.ActApplication.Instance.ApplicationState.CurrentContact;

            //Your code here, you can access the current contact via:
            Act.Framework.Activities.ActivityType[] activityTypes = Act.UI.ActApplication.Instance.ActFramework.Activities.GetActivityTypes();
            Act.Framework.Activities.ActivityTemplate aTemplate;

            foreach (Act.Framework.Activities.ActivityType a in activityTypes)
            {
                if (a.Name == "To-do")
                {
                    string regarding = "Mail In";
                    string details = "Mail has been received for this client\n\n Details:\n\nBulk Scan: Yes / No";

                    aTemplate = Act.UI.ActApplication.Instance.ActFramework.Activities.CreateActivity(a);
                    aTemplate.ActivityContacts.Add(c);
                    aTemplate.StartTime = System.DateTime.Now;
                    aTemplate.EndTime = System.DateTime.Now.AddMinutes(5);
                    aTemplate.Regarding = regarding;
                    aTemplate.Details = details;
                    aTemplate.Update();
                }
            }

            c.Update();

            Act.UI.ActApplication.Instance.RefreshLoadedViews();
        }
    }
}

 


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