Community
Showing results for 
Search instead for 
Do you mean 
Reply

Access a custom product field from the SDK

Tuned Listener
Posts: 10
Country: United_Kingdom

Access a custom product field from the SDK

Hi,

 

Ive added a custom field into the proudcts table via the following code

 

FIELD_FREESTOCK_DESC = "Free Stock";

FIELD_FREESTOCK_ALIAS = "FREE_STOCK";

 

FieldDescriptor stockField = new FieldDescriptor(ProductEntityDefinition.FIELD_FREESTOCK_DESC,
ProductEntityDefinition.FIELD_FREESTOCK_ALIAS,
RecordType.Product, FieldDataType.Number);
Framework.Fields.Save(stockField);

 

When trying to access it using the following it errors saying the real name is invalid, is there another more failsafe way of accessing the field ?

 

CustomEntityFieldDescriptor fldStock =
actFwk.Products.OpportunityProductManager.GetCustomEntityFieldDescriptor(ProductEntityDefinition.FIELD_FREESTOCK_ALIAS, FieldNameType.Alias);

Copper Contributor
Posts: 14
Country: Germany

Re: Access a custom product field from the SDK

You could try getting all descriptors and then searching for the right one among them. Also it makes sense to try forming a name of the field in a form of "TableName.FieldName".

Tuned Listener
Posts: 10
Country: United_Kingdom

Re: Access a custom product field from the SDK

The problem is that their dosnt seem to be a usable descriptor ...GetFieldDescriptors dosnt return custom fields

 

Ive now managed to get a MutableEntityFieldDescriptor for the correct field ...but turns out that a act product is not castable to a MutableEntity 

Copper Contributor
Posts: 14
Country: Germany

Re: Access a custom product field from the SDK

I looked into my code, this is how I get all fields for products (starting from Act 12)

 ActFramework.Products.OpportunityProductManager.GetFieldDescriptors();

 Product is not castable to MutableEntity, but OpportunityProduct derives from it.

Bronze Super Contributor
Posts: 1,231
Country: USA

Re: Access a custom product field from the SDK

[ Edited ]

I created a function to return the field descriptor using the alias name. Here is the code below.

 

First get the CustomSubEntityManager from our host the ACTAPP (HostFramework.Products.OpportunityProductManager)

 

Then call the GetFieldDescriptorByAlias function to get the CustomEntityFieldDescriptor

 

Dim EntityManagerOpportunityProduct As CustomSubEntityManager(Of OpportunityProduct) = HostFramework.Products.OpportunityProductManager
Dim myCustomFieldDescriptor As Act.Framework.CustomEntities.CustomEntityFieldDescriptor = Durkin.Common.Classes.Products.GetFieldDescriptorByAlias("MyCost", EntityManagerOpportunityProduct)

 

Here is the method called

 Public Shared Function GetFieldDescriptorByAlias(ByVal sAliasName As String, _
                                                     ByVal manager As CustomSubEntityManager(Of OpportunityProduct)) As Act.Framework.CustomEntities.CustomEntityFieldDescriptor
        Try
            '------------------------------------------------------------
            ' DEV NOTE 5.0.0.x
            ' Used for act 2010 and greater
            ' Returns a CustomEntityFieldDescriptor  
            '------------------------------------------------------------

            '------------------------------------------------------------
            ' Check all fields in the GetCustomEntityFieldDescriptors
            ' And return the fields where sAliasName = cField1.Alias
            ' If the field does not have any alias then ColumnName is used
            ' Wish the act! dev guys would standardize ALIAS on system fields :(
            '----------------------------------------------------------------
            For Each cField1 As Act.Framework.CustomEntities.CustomEntityFieldDescriptor In manager.GetCustomEntityFieldDescriptors()

                If Not cField1.Alias Is Nothing Then
                    If sAliasName.ToUpper = cField1.Alias.ToUpper Then
                        Return cField1
                        Exit For
                    Else
                        '------------------------
                        ' ?? Bug in .NET 2.0 or ACT!
                        ' KEEP THIS LINE
                        '------------------------
                        Dim sDummyString As String = "sDummyString"
                    End If
                Else
                    If sAliasName.ToUpper = cField1.ColumnName.ToUpper Then
                        Return cField1
                        Exit For
                    Else
                        '------------------------
                        ' ?? Bug in .NET 2.0 or ACT!
                        ' KEEP THIS LINE
                        '------------------------
                        Dim sDummyString As String = "sDummyString"
                    End If
                End If

            Next

            Return Nothing

        Catch ex As Exception
            Throw ex
        End Try

    End Function

 

Hope this helps

-- Jim Durkin

 

Tuned Listener
Posts: 10
Country: United_Kingdom

Re: Access a custom product field from the SDK

Thats solves getting the descriptor, thanks.    Now to have to work out how to get from a Product class to an OpportunityProduct one for it to be usable ...

Copper Contributor
Posts: 14
Country: Germany

Re: Access a custom product field from the SDK

You can't get an OpportunityProduct object out of a Product object. The Product object is something like a template for OpportunityProducts, the class has some standard uncustomizable fields. The only thing that connects them together is that you can specify a ProductID in an OpportunityProduct object.

To get an existing OpportunityProduct object, use variaous methods that are provided by ActFramework.Products.OpportunityProductManager. Also, you can get existing OpportunityProducts using the GetProducts method of the Opportunity class.

Tuned Listener
Posts: 10
Country: United_Kingdom

Re: Access a custom product field from the SDK

Ok, how would i go about getting a list of the products on the system to be used in a drop down list for selection ...GetOpportuntiyProudcts wants a list of guids to return ..wheres i want all of them

Bronze Super Contributor
Posts: 1,231
Country: USA

Re: Access a custom product field from the SDK

[ Edited ]

 

This is sudo code...

 

' Create the UI ComboBox control

Dim cboProducts As ComboBox = New ComboBox

cboProducts.DisplayMember = "Name"
cboProducts.ValueMember = "ID"

 

'-----------------------------------------------------------------------------
' 1) Loop thru all the products

'     attaching each product to the ComboBox.items collection
'-----------------------------------------------------------------------------
Dim cProduct As Act.Framework.Opportunities.Product
For Each cProduct In HostFramework.Products.GetProducts(Nothing)
     cboProducts.Items.add(cProduct )

Next

 

OR

'-----------------------------------------------------------------------------
' 2) Attach the ProductList collection directly to the DataSource

'-----------------------------------------------------------------------------

cboProducts.DataSource = HostFramework.Products.GetProducts(Nothing)

 

 

Hope this helps

-- Jim Durkin

Tuned Listener
Posts: 10
Country: United_Kingdom

Re: Access a custom product field from the SDK

Thanks ..ive sorted it now using the GetCustomEntites method of the OpportunityProductManager