01-29-2009 09:43 PM
Hi,
I am new in this environment and I have a task that I need to do for my boss. Ultimately, I need to read certain number of informations from multiple local sources ( excel, SQL ) and validate the data (using our own business logic) and then update the oportunity amount field and create another instance of an opportunity in Act.
I am a VB coder and I am hoping if someone could give me some idea on how to achieve this using the SDK (2007 9.0)
01-30-2009 07:38 AM
dim actfwk as new act.framweork.actframework
actfwk.logon(pad,user,password)
dim opp as act.framework.opportunities.opportunity = actfwk.opportunities.createopportunity(paramaters see below)...
'cant remember if you need to call update or not as I'm not at my work computer
opp.update()
Overloads Public Function CreateOpportunity( _ ByVal name As String, _ ByVal contact As Contact, _ ByVal status As OpportunityStatus, _ ByVal stage As Stage, _ ByVal probability As Integer, _ ByVal estCloseDate As Date, _ ByVal makeItPrivate As Boolean _ ) As Opportunity
Tom
01-30-2009 09:31 AM
TDavis,
Thank you for the response.
I am just curious if there's an ID that I can use to create a new opportunity to a specific contact. I've searched around the sdk docs and I don't see any option to retreive the record ID on a contact level. I am hesitant to use the Fullname since we have legit records that have similar names. Do you have any recommendation?
01-30-2009 05:00 PM - edited 01-30-2009 05:02 PM
Hi,
I was trying to use the create opportunity function that you recommended but I am always getting this error "Object reference not set to an instance of an object. " (particularly on my varcontacts in createopportunity function)
I posted a summary of my code for your reference.
ActFwkLogin()
Dim mDays As Date = Now.AddDays(30)
Dim mValue As String = Act.Framework.Opportunities.OpportunityField.Status.ToString()Dim mOpptyName As String = "MYNEWOPPORTUNITY"Dim cField As Act.Framework.Opportunities.OpportunityFieldDescriptor = ActFwk.Opportunities.GetOpportunityFieldDescriptors("25")
Dim sCriteria() As Act.Shared.Collections.SortCriteria = {New Act.Shared.Collections.SortCriteria(cField, System.ComponentModel.ListSortDirection.Ascending)}
Dim clist As Act.Framework.Opportunities.OpportunityList = ActFwk.Opportunities.GetOpportunities(sCriteria)Dim varcontacts As Contact
varcontacts = ActFwk.Contacts.GetMyRecord()
For Each contact As Act.Framework.Opportunities.Opportunity In clist'-----some biz logic here-----'
Dim opp As Act.Framework.Opportunities.Opportunity = ActFwk.Opportunities.CreateOpportunity(mOpptyName, varcontacts, OpportunityStatus.Open, Nothing, 0, mDays, False)
Next
logout()
02-02-2009 01:42 AM
You are mixing up your contacts and opportunities....I have mostly just commented above your code not corrected it so don't just copy and paste back in...
'you should be getting a contact field here to sort by, not an opp one
Dim cField As Act.Framework.Opportunities.OpportunityFieldDescriptor = ActFwk.Opportunities.GetOpportunityFieldDescriptors("25")Dim sCriteria() As Act.Shared.Collections.SortCriteria = {New Act.Shared.Collections.SortCriteria(cField, System.ComponentModel.ListSortDirection.Ascending)}
'cList should be a contact list ie dim cList as act.framework.contacts.contactlist = actfwk.contacts.getcontacts(sCriteria)
'if you only want one reacord you dont have to loop you can just get one contact as act.framwork.contacts.contact
Dim clist As Act.Framework.Opportunities.OpportunityList = ActFwk.Opportunities.GetOpportunities(sCriteria)
'dont need this bit
Dim varcontacts As Contactvarcontacts = ActFwk.Contacts.GetMyRecord()
'this should be for each contact as act.framework.contacts.contact asyou are looping a contact list
For Each contact As Act.Framework.Opportunities.Opportunity In clist'-----some biz logic here-----'
Dim opp As Act.Framework.Opportunities.Opportunity = ActFwk.Opportunities.CreateOpportunity(mOpptyName, contact, OpportunityStatus.Open, Nothing, 0, mDays, False)
02-02-2009 11:05 PM
Hi,
I cleaned up my code and I am still confused on how to achieve the contact information in this manner.
Basically, what I am trying to do is to read on all existing opportunities, if it matches my criteria, I will then create a new opportunity for that particular contact.
The code below is still giving me a "null" and instance object error. I would appreciate your help.
actlogin()
'----
'codes to read all opportunities
'------
'if criteria matched the item
'this set of code will be called
Dim NewCloseDate As Date = Now.AddDays(45)
Dim NewOpportunityName As String = "New"
Dim contact As Act.Framework.Contacts.Contact
'The contact is still a problem.
Dim opp As Act.Framework.Opportunities.Opportunity = ActFwk.Opportunities.CreateOpportunity(NewOpportunityName, contact, OpportunityStatus.Open, Nothing, 0, NewCloseDate, False)
'---------------------------------
actlogoff()
02-03-2009 12:32 AM
When yo read the opps and you find one that matches your criteria get the contact associated with that opp from its propety ie...
(sudo code)
for each opp as opportunity
'business logic here
if true contact = opp.contact
'create new opp here
next
02-03-2009 08:36 AM
Hi,
In my previous message, my concern is the contact parameter of the createopportunity.
I have no problem with my existing logic.
Do you know by any chance why I am getting an error in the contact parameter?
02-03-2009 02:36 PM - edited 02-03-2009 02:39 PM
NewDev,
This is copied straight from the ACT! SDK Samples included with the SDK download. You should be able to copy and paste it into your code and it should work as long as you are logged into an ACT framework instance.
Maybe this working example could help you narrow down where you are getting your Null reference error?
'Example 2 'This example creates an Opportunity and then populates several of the Opportunities fields. 'The opportunity. Dim oOpp As Opportunity 'Needed variables. 'The Opportunity Name. Dim sName As String = "myOpp" 'The contact to create the opportunity for. Dim cList As ContactList = ActFwk.Contacts.GetContacts(Nothing) Dim cContact As Contact = cList(0) 'The Opportunity Status (Inactive, Lost, Open, Won.) Dim oStatus As OpportunityStatus = OpportunityStatus.Open 'The Opportunity Stage. Dim pProcess() As Process = ActFwk.StageManager.ActiveProcesses Dim sStages() As Stage = pProcess(0).Stages Dim oStage As Stage = sStages(0) 'The Opportunity Probability. Dim iProbability As Integer = 50 'The Opportunities Estamated Close Date. Dim dEstCloseDate As Date = System.DateTime.Now.AddDays(30) 'Should this Opportunity be Public or Private? Dim bMakeItPrivate As Boolean = False 'We'll use these next set of variables after the creation of the Opportunity. Dim pList As ProductList = ActFwk.Products.GetProducts(Nothing) Dim dAmount As Decimal = 10.0 Dim pProduct As Product = pList(0) Dim sDetails As String = "This opportunity brought to you by the ACT! SDK." Dim sReason As String = "Because we like you." Dim dOpenDate As Date = System.DateTime.Now 'The call to CreateOpportunity. oOpp = ActFwk.Opportunities.CreateOpportunity(sName, cContact, oStatus, oStage, iProbability, dEstCloseDate, bMakeItPrivate) 'And continue to populate fields... oOpp.AddProduct(pProduct, dAmount) oOpp.Amount = dAmount oOpp.Details = sDetails oOpp.Reason = sReason oOpp.OpenDate = dOpenDate MessageBox.Show("Opportunity " & sName & " created for " & cContact.FullName)
From your posts you are still having trouble with 'null' reference for your contact. I would make sure that this code works before moving foward.
So pay special attention to the part of the code where you are setting your contact object to whatever contact happens to be at the top of an unsorted ContactList.
'The contact to create the opportunity for. Dim cList As ContactList = ActFwk.Contacts.GetContacts(Nothing) Dim cContact As Contact = cList(0)
Obviously, you won't want to do this in your plugin 'for real' but it might help you find where you are getting your error.
Hope this helps,
02-03-2009 02:46 PM - edited 02-03-2009 02:47 PM
Actually I think this might be more of what you are looking for?
'Example 2 'This example displays the Contact associated with an Opportunity. Dim oList As OpportunityList Dim opp As Opportunity Dim cContact As Contact oList = ActFwk.Opportunities.GetOpportunities(Nothing) If Not (oList Is Nothing) Then opp = oList(0) Dim cList As List(Of Contact) = opp.Contacts cContact = cList(0) MessageBox.Show(opp.Name & " - " & cContact.FullName) Else MessageBox.Show("There are no Opportunities.") End If
And then rather that simply displaying the contact in a messagebox you can make use of it from there?