Saving Data to Custom Fields on Product - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Saving Data to Custom Fields on Product

  • Saving Data to Custom Fields on Product
  • I am having an issue where I have created a Custom Field on a
    Product Type called "Sample". The name of this field is DetailField.  
    I have a product  of Product Type Sample and I would like to save a block
    of text to this Custom Field of my Product.  I have tried

    This corrupts the prodcuct Data:
    Product.SetValue(“DetailStringResources”, “<b>my html formatted string

    This throws an Error “Not a PersistenceCapable instance or type
    was not enhanced.”:  Product.SetFieldValue(“DetailStringResources”,
    “<b>my html formatted string here</b>”);

    What am I missing and what is the proper way to set that field
    to the value that I want?  I did attempt to find API documentation related
    to this but there was nothing that addressed custom fields on products (via
    Product Type) Thanks!
  • Hello Walt,

    We have already provided you with a response in the support ticket you had open on the same topic. For your convenience please find our response quoted below as well.

    About the first paragraph you have wrote I guess you are creating this custom field from the backend right? not using some code ? The code for creating a custom field is here : but I guess you are doing the creation from the backend. If so everything in the creating of the field should be correct, if you haven't mark it as hidden can you confirm it is visible on the product edit screen ?

     it should look like see beforeChange.png attached bellow.

     In order to use this field  via the API (which is your second question) you need to do the fallowing :
                 //lines just to get the product I want to be updated 
         var manager = CatalogManager.GetManager();
                 var productType = manager.GetProductTypes().Where(pt => pt.TitlePlural == "Sample").Single();
                 var firstSampleProduct = manager.GetProducts(productType.ClrType).First(); // just take one
                 //important lines  for the custom field change.          
         firstSampleProduct.SetValue("DetailStringResources", "changed via API call");

     Then you can verify it is changed as it is shown in afterChange.png attached bellow.

     Documentation for that can be found here

     I hope it is clear and working now on your side.
     Please let me know if you need future assistance.

    Nayden Gochev

    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items