Community
Showing results for 
Search instead for 
Do you mean 
Reply

Hot to get the opportunity ID

Copper Contributor
Posts: 41
Country: USA

Hot to get the opportunity ID

Hello All!

 

I need to get the opportunity ID through vb code. Everything I try does not work. Below is a sample of what I have tried? Does anybody have an idea how to get the opp ID??

 

Dim fdOppID As MutableEntities.MutableEntityFieldDescriptor = ActFwk.Opportunities.GetOpportunityFieldDescriptor("OPPORTUNITYID", MutableEntities.FieldNameType.Alias)

 

Bop Lozinak

Bob Lozinak
Twelve/Three Marketing, Inc.
Software Developer
Nickel Contributor
Posts: 175
Country: USA

Re: Hot to get the opportunity ID

Bob,

 

Generally speaking, it's usually better to use the GetMutableFieldDescriptor methods instead of the object specific ones (Opportunity, company, contact, etc.). I know in the past they (the object specific ones) had some issues, but I'm not sure if they have all been resolved yet.

 

Here's a bunch of code I use to get Opportunity information. It basically makes DataTables of Opportunities, Companies in the Opportunity, and Products in the Opportunity. The DataTables are close to, if not exact replicas of the actual tables in ACT!. I do this to make saving the data to a different SQL Server easier (the TransferData call). I've posted the entire batch of code because it could be useful to others.

 

 Dim actf As New Act.Framework.ActFramework
            actf.LogOn(strLiveDB, userName, password)

            Dim oppList As Act.Framework.Opportunities.OpportunityList
            Dim od As Act.Framework.MutableEntities.MutableEntityFieldDescriptor = actf.Opportunities.GetMutableEntityFieldDescriptor("VWT_OPPORTUNITY_STAGE_PROCESS.PROCESS", Act.Framework.MutableEntities.FieldNameType.Real)
            Dim filter As New Act.Framework.ComparisonFilterCriteria(od, Act.Framework.ComparisonFilterCriteria.Operation.Equals, "Filter String")
            oppList = actf.Opportunities.GetOpportunities(Nothing, New Act.Framework.IFilterCriteria() {filter})

            dt = New DataTable 'opportunities
            dt.Columns.Add("ID", GetType(String))
            Dim fds() As Act.Framework.MutableEntities.MutableEntityFieldDescriptor = actf.Opportunities.GetMutableEntityFieldDescriptors()
            For Each fd As Act.Framework.MutableEntities.MutableEntityFieldDescriptor In fds
                Dim dc As New DataColumn(fd.Name.Replace(fd.TableName & ".", ""))

                Select Case fd.ACTFieldType
                    Case Is = Act.Framework.Database.FieldDataType.Character, Act.Framework.Database.FieldDataType.Memo
                        dc.DataType = GetType(String)
                    Case Is = Act.Framework.Database.FieldDataType.Date, Act.Framework.Database.FieldDataType.DateTime
                        dc.DataType = GetType(DateTime)
                    Case Is = Act.Framework.Database.FieldDataType.YesNo
                        dc.DataType = GetType(Boolean)
                    Case Is = Act.Framework.Database.FieldDataType.Number, Act.Framework.Database.FieldDataType.Currency, Act.Framework.Database.FieldDataType.Decimal, Act.Framework.Database.FieldDataType.TinyInt
                        dc.DataType = GetType(Double)
                End Select

                dt.Columns.Add(dc)
            Next

            dtSubTop = New DataTable   'companies
            dtSubTop.Columns.Add("OppID", GetType(String))
            Dim fdsComp() As Act.Framework.MutableEntities.MutableEntityFieldDescriptor = actf.Companies.GetMutableEntityFieldDescriptors()
            For Each fd As Act.Framework.MutableEntities.MutableEntityFieldDescriptor In fdsComp
                Dim dc As New DataColumn(fd.Name.Replace(fd.TableName & ".", ""))
                Select Case fd.ACTFieldType
                    Case Is = Act.Framework.Database.FieldDataType.Character, Act.Framework.Database.FieldDataType.Memo
                        dc.DataType = GetType(String)
                    Case Is = Act.Framework.Database.FieldDataType.Date, Act.Framework.Database.FieldDataType.DateTime
                        dc.DataType = GetType(DateTime)
                    Case Is = Act.Framework.Database.FieldDataType.YesNo
                        dc.DataType = GetType(Boolean)
                    Case Is = Act.Framework.Database.FieldDataType.Number, Act.Framework.Database.FieldDataType.Currency, Act.Framework.Database.FieldDataType.Decimal, Act.Framework.Database.FieldDataType.TinyInt
                        dc.DataType = GetType(Double)
                End Select
                dtSubTop.Columns.Add(dc)
            Next

            dtSubBottom = New DataTable   'Products
            dtSubBottom.Columns.Add("OppID", GetType(String))
            Dim fdsProd() As Act.Framework.MutableEntities.MutableEntityFieldDescriptor = actf.Products.OpportunityProductManager.GetMutableEntityFieldDescriptors()
            For Each fd As Act.Framework.MutableEntities.MutableEntityFieldDescriptor In fdsProd
                Dim dc As New DataColumn(fd.Name.Replace(fd.TableName & ".", ""))
                Select Case fd.ACTFieldType
                    Case Is = Act.Framework.Database.FieldDataType.Character, Act.Framework.Database.FieldDataType.Memo
                        dc.DataType = GetType(String)
                    Case Is = Act.Framework.Database.FieldDataType.Date, Act.Framework.Database.FieldDataType.DateTime
                        dc.DataType = GetType(DateTime)
                    Case Is = Act.Framework.Database.FieldDataType.YesNo
                        dc.DataType = GetType(Boolean)
                    Case Is = Act.Framework.Database.FieldDataType.Number, Act.Framework.Database.FieldDataType.Currency, Act.Framework.Database.FieldDataType.Decimal, Act.Framework.Database.FieldDataType.TinyInt
                        dc.DataType = GetType(Double)
                End Select
                dtSubBottom.Columns.Add(dc)
            Next

            'FILL DATA-------------------------
            If oppList.Count > 0 Then
                For Each opp As Act.Framework.Opportunities.Opportunity In oppList
                    Dim dr As DataRow = dt.NewRow
                    dr("ID") = opp.ID.ToString
                    For Each fd As Act.Framework.MutableEntities.MutableEntityFieldDescriptor In fds
                        Dim obj As Object = fd.GetValue(opp)
                        If obj Is Nothing Then
                            dr(fd.Name.Replace(fd.TableName & ".", "")) = DBNull.Value
                        Else
                            dr(fd.Name.Replace(fd.TableName & ".", "")) = obj
                        End If
                    Next
                    dt.Rows.Add(dr)

                    Dim companies As Act.Framework.Companies.CompanyList = opp.GetCompanies(Nothing)
                    For Each comp As Act.Framework.Companies.Company In companies
                        Dim drTop As DataRow = dtSubTop.NewRow
                        drTop("OppID") = opp.ID.ToString 'comp.ParentID.ToString
                        For Each fd As Act.Framework.MutableEntities.MutableEntityFieldDescriptor In fdsComp
                            Dim obj As Object = fd.GetValue(comp)
                            If obj Is Nothing Then
                                drTop(fd.Name.Replace(fd.TableName & ".", "")) = DBNull.Value
                            Else
                                drTop(fd.Name.Replace(fd.TableName & ".", "")) = obj
                            End If
                        Next
                        dtSubTop.Rows.Add(drTop)
                    Next
                    ' opp.GetProducts(Nothing)
                    Dim prods As Act.Framework.CustomEntities.CustomEntityList(Of Act.Framework.Opportunities.OpportunityProduct) = opp.GetProducts(Nothing)
                    For Each prod As Act.Framework.Opportunities.OpportunityProduct In prods
                        Dim drBot As DataRow = dtSubBottom.NewRow
                        drBot("OppID") = opp.ID.ToString 'prod.OpportunityID.ToString
                        For Each fd As Act.Framework.MutableEntities.MutableEntityFieldDescriptor In fdsProd

                            Dim obj As Object = fd.GetValue(prod)
                            If obj Is Nothing Then
                                drBot(fd.Name.Replace(fd.TableName & ".", "")) = DBNull.Value
                            Else
                                drBot(fd.Name.Replace(fd.TableName & ".", "")) = obj
                            End If
                        Next
                        dtSubBottom.Rows.Add(drBot)
                    Next

                Next

                TransferData(dt, dtSubBottom, dtSubTop)

            End If

            actf.LogOff()

 

Copper Contributor
Posts: 41
Country: USA

Re: Hot to get the opportunity ID

Thanks that did the trick.

Bob Lozinak
Twelve/Three Marketing, Inc.
Software Developer