02-13-2015 01:18 PM
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(); } } }
02-13-2015 01:28 PM
Arrays aren't a collection so you can't enumerate them using a for...each.
Stan
02-13-2015 01:40 PM
02-13-2015 02:27 PM - edited 02-13-2015 02:30 PM
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.
02-13-2015 03:13 PM
02-13-2015 03:23 PM
02-13-2015 03:26 PM
02-14-2015 12:50 PM
02-14-2015 11:58 PM
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.
02-15-2015 12:33 PM
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(); } } }