Community
Showing results for 
Search instead for 
Do you mean 
Reply

How to add opportunity via SDK

Loyal Listener
Posts: 19
Country: USA

How to add opportunity via SDK

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?

 

Thanks!

Employee
Posts: 1,163
Country: USA

Re: How to add opportunity via SDK

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.

 

 

Snippet

OpportunityManager OppMan = new OpportunityManager(ActApp.ActFramework);
Stage[] stages = _ActApp.ActFramework.StageManager.GetStages("Initial Communication");           
Opportunity o =  OppMan.CreateOpportunity("Test123"OpportunityStatus.Open, stages[0], DateTime.Now.AddDays(-1), false);
o.Update();

 

Activities:

Snippet

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.ActivityContacts.Add(contact);
newActivity.Regarding = "TEST";
newActivity.StartTime = startTime;
newActivity.EndTime = endTime;
newActivity.Details = " ";
newActivity.Organizer = cdg;
newActivity.IsAlarmed = true;
newActivity.LeadMinutes = 10;
newActivity.Update();

Notes:

Snippet

NoteType[] noteTypes = ActApp.ActFramework.Notes.GetNoteTypes();
ActApp.ActFramework.Notes.CreateNote(noteTypes[0], "New Test Note", System.DateTime.Now, false, ActApp.ActFramework.Contacts.GetMyRecord());
Matthew Wood
Act! SDK Support
Community Moderator
Loyal Listener
Posts: 19
Country: USA

Re: How to add opportunity via SDK

[ Edited ]

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?

Employee
Posts: 1,163
Country: USA

Re: How to add opportunity via SDK

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?

Matthew Wood
Act! SDK Support
Community Moderator
Loyal Listener
Posts: 19
Country: USA

Re: How to add opportunity via SDK

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!