Community
Showing results for 
Search instead for 
Do you mean 
Reply

Getting Opportunity Products via the ACT! SDK

Employee
Posts: 3
Country: USA

Getting Opportunity Products via the ACT! SDK

// Assuming that you have an opportunity called opp

// SortCriteria can be null

SortCriteria[] sortCriteria = null;

CustomEntityList productList = opp.GetProducts(sortCriteria);


//The standard product fields can be accessed via properties off of the Product object

System.Console.WriteLine("The product discount is {0}", productList[0].Discount.ToString());


// For custom product fields it's similar to other entities

// Assuming a custom string field called SKU which gets created

// in the database as "CUST_SKU_021944668"

object sku = productList[0].Fields["TBL_PRODUCTSERVICE.CUST_SKU_021944668", true];

if (sku != null)

System.Console.WriteLine("The SKU for the product is {0}, sku.ToString());

else

System.Console.WriteLine("The SKU for the product is NULL");


// If you need an actual field descriptor it can be gotten like this:

// Gets the field descriptor for the NAME field.

CustomEntityFieldDescriptor fldDesc = this.ActFramework.Products.OpportunityProductManager.GetCustomEntityFieldDescriptor("TBL_PRODUCTSERVICE.NAME", true);

System.Console.WriteLine("The Display Name of the field is {0}", fldDesc.DisplayName);

Nickel Elite Contributor
Posts: 937
Country: USA

Re: Getting Opportunity Products via the ACT! SDK

Thanks George!

Tuned Listener
Posts: 21
Country: USA

Re: Getting Opportunity Products via the ACT! SDK

 

The idea here works fine and we used the idea there when we develop a plugins for QwikQuote recently.

 

One little point is to figure out the exact internal field name after you successfully added the custom filed to the Product entity – especially the magic number at the ending part of the custom field. The dilemma is as long as you do not know that number, you cannot get the Custom Entity Field Descriptor of the custom field you added.

 

In process of developing a plugins for QwikQuote in a QwikQuote Customization project recently, we use the code similar as below to list all the Custom Entity Field Descriptors

 

Dim aryCustomEntityFieldDescriptor() As Act.Framework.CustomEntities.CustomEntityFieldDescriptor

    aryCustomEntityFieldDescriptor = m_LiveActFW.Products.OpportunityProductManager.GetCustomEntityFieldDescriptors()

For Each soppPSCustomFieldDescriptor As CustomEntityFieldDescriptor In aryCustomEntityFieldDescriptor 

    With soppPSCustomFieldDescriptor                       

            Debug.Print (.TableName & "    " & .ColumnName & "    " & .Name)

    End With

Next  

And the typical output is as below

    TBL_PRODUCTSERVICE    CUST_SDKProduct_011749238        TBL_PRODUCTSERVICE.CUST_SDKProduct_011749238

    TBL_PRODUCTSERVICE    CUST_ExchangeRage_093258479      TBL_PRODUCTSERVICE.CUST_ExchangeRage_093258479

    TBL_PRODUCTSERVICE    UNITPRICE                        TBL_PRODUCTSERVICE.UNITPRICE

    TBL_PRODUCTSERVICE    UNITCOST                         TBL_PRODUCTSERVICE.UNITCOST

    TBL_PRODUCTSERVICE    ITEMCODE                         TBL_PRODUCTSERVICE.ITEMCODE

    TBL_PRODUCTSERVICE    EDITDATE                         TBL_PRODUCTSERVICE.EDITDATE

    TBL_PRODUCTSERVICE    CREATEDATE                       TBL_PRODUCTSERVICE.CREATEDATE

    TBL_PRODUCTSERVICE    EXTENDEDAMT                      TBL_PRODUCTSERVICE.EXTENDEDAMT

    TBL_PRODUCTSERVICE    DISCOUNTPRICE                    TBL_PRODUCTSERVICE.DISCOUNTPRICE

    TBL_PRODUCTSERVICE    QUANTITY                         TBL_PRODUCTSERVICE.QUANTITY

    TBL_PRODUCTSERVICE    CUST_ShippingWeight_100806979    TBL_PRODUCTSERVICE.CUST_ShippingWeight_100806979

    TBL_PRODUCTSERVICE    UNITDISCOUNT                     TBL_PRODUCTSERVICE.UNITDISCOUNT

    TBL_PRODUCTSERVICE    ITEMTYPE                         TBL_PRODUCTSERVICE.ITEMTYPE

    TBL_PRODUCTSERVICE    NAME                             TBL_PRODUCTSERVICE.NAME

 

With a little intelligent in string processing one can figure out which name is the right one to use

    'TBL_PRODUCTSERVICE    CUST_SDKProduct_011749238        TBL_PRODUCTSERVICE.CUST_SDKProduct_011749238

    'TBL_PRODUCTSERVICE    CUST_ExchangeRage_093258479      TBL_PRODUCTSERVICE.CUST_ExchangeRage_093258479

    'TBL_PRODUCTSERVICE    CUST_ShippingWeight_100806979    TBL_PRODUCTSERVICE.CUST_ShippingWeight_100806979

 

And then you can use the code similar as below to read from or writhe to the Product Custom Field:

Dim thisCustomEntityFieldDescriptor As CustomEntityFieldDescriptor = Nothing

    thisCustomEntityFieldDescriptor = m_LiveActFW.Products.OpportunityProductManager.GetCustomEntityFieldDescriptor("TBL_PRODUCTSERVICE.CUST_SDKProduct_011749238", true)

Dim CustFieldVal_Old As String      ' Nothing there in yet.

    CustFieldVal_Old = thisCustomEntityFieldDescriptor.GetValue (soppProductServiceItem)                                      

                        thisCustomEntityFieldDescriptor.SetValue (soppProductServiceItem, "Test Value!!!")                    

Dim CustFieldVal_New As String      ' Now new value is: Test Value!!!

    CustFieldVal_New = thisCustomEntityFieldDescriptor.GetValue (soppProductServiceItem)