03-07-2011 02:03 PM
I've looked through the code samples here on the message board and have found older messages that refer to overloads that don't seem to be available in the latest version of the SDK (2011). Could you give me example code for adding an opportunity to a contact using 2011?
I haven't looked yet for samples of adding activities or notes, but I'll need those next. Could you include examples of all three of these actions?
03-07-2011 02:58 PM
This will create a new opportunity. From here can set the RecordManager, Reason etc. In all these the only variable that I do not initialize within the snippet is ActApp, which is the Act.UI.ActApplication object from within a plugin.
OpportunityManager OppMan = new OpportunityManager(ActApp.ActFramework);
Stage stages = _ActApp.ActFramework.StageManager.GetStages("Initial Communication");
Opportunity o = OppMan.CreateOpportunity("Test123", OpportunityStatus.Open, stages, DateTime.Now.AddDays(-1), false);
ContactList allCL = ActApp.ActFramework.Contacts.GetContacts(null);
contact = ActApp.ApplicationState.CurrentContact;
System.DateTime startTime = System.DateTime.Now.AddMinutes(10);
System.DateTime endTime = System.DateTime.Now.AddMinutes(20);
User users = ActApp.ActFramework.Users.ActiveUsers;
CalendarDelegateGrantor cdg = ActApp.ActFramework.CalendarDelegates.GetCalendarDelegateGrantorByAccessorId(users[users.Length - 1].ID);
ActivityTemplate newActivity = ActApp.ActFramework.Activities.CreateActivity(StandardActivityType.Meeting);
newActivity.Regarding = "TEST";
newActivity.StartTime = startTime;
newActivity.EndTime = endTime;
newActivity.Details = " ";
newActivity.Organizer = cdg;
newActivity.IsAlarmed = true;
newActivity.LeadMinutes = 10;
NoteType noteTypes = ActApp.ActFramework.Notes.GetNoteTypes();
ActApp.ActFramework.Notes.CreateNote(noteTypes, "New Test Note", System.DateTime.Now, false, ActApp.ActFramework.Contacts.GetMyRecord());
03-11-2011 05:12 AM - edited 03-11-2011 05:13 AM
When I double-click the activity created with the snippet above in the Act! UI, I get a message saying, "You do not have sufficient rights to view this activity."
Is there another step I'm missing?
03-11-2011 06:07 AM
Are you logged in as an administrator and are you able to view other activities created by the CalendarDelegateGrantor used in the sample? Did you do this in the demo database?
03-11-2011 06:50 AM
I was setting the CalendarDelegateGrantor to the user who created the activity, but I was logged in as myself (administrator).
After some experimenting with the CalendarDelegateGrantor I realized that if I closed Act! and re-opened it, I was then able to open the activity. (I had been leaving Act! open and just refreshing the list after deleting the database via the SDK and exporting a new test batch of records.)
Many thanks for all your help!