Adding Custom Fields Option to Custom Modules - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Adding Custom Fields Option to Custom Modules

  • Adding Custom Fields Option to Custom Modules
  • Hey,

    I just went through and added a custom module based off of the Products module. I want the user to have the option to add a custom field to this module.  Can you give me a quick run through and hopefully some sample code for the Install procedure that will allow my custom module to use the Custom Fields option.

    Just to clarify: I can add fields as needed in the code, but I need to allow the user to add a custom field (like they can in news or elsewhere)

    Thanks
  • Hello,

    Here is the code you must add in your definitions file:

    CommandWidgetElement customFields = new CommandWidgetElement(settings.Items)
                
                    Name = "ProductsCustomFields",
                    CommandName = "moduleEditor",
                    ButtonType = CommandButtonType.SimpleLinkButton,
                    Text = "CustomFields",
                    ResourceClassId = typeof(ProductsResources).Name,
                    WidgetType = typeof(CommandWidget),
                    IsSeparator = false
                ;
                settings.Items.Add(customFields);

    This add the custom field in the settings section.

    Then you must add a new dialog definition:
    DialogElement moduleeditorelement = DefinitionsHelper.CreateDialogElement(productsGridView.DialogsConfig,                       "moduleEditor", "ModuleEditorDialog", parameters);
      
                productsGridView.DialogsConfig.Add(moduleeditorelement);

    Jocelyn
  • Thanks!

    Can you tell me what I should be using for the parameters parameter of CreateDialogElement
    i'm currently trying variations of the code below, but I'm receiving javascript error Could not load type ''. on the custom fields dialog
    This is the url thats throwing the 500. note contentType is blank
    localhost:60876/.../

    parameters = string.Concat(
                    "?ControlDefinitionName=",
                    ProductsDefinitions.BackendDefinitionName,
                    "&ViewName=",
                    ProductsDefinitions.BackendCustomFieldsDefinitionName,
                          "&contentType=", typeof(ProductItem).AssemblyQualifiedName,
                          "&typeName=", typeof(ProductItem).AssemblyQualifiedName);
                   // "ProductsCustomFieldsBackend"
     
                DialogElement moduleEditorElement = DefinitionsHelper.CreateDialogElement(productsGridView.DialogsConfig, "moduleEditor", "ModuleEditorDialog", parameters);
                productsGridView.DialogsConfig.Add(moduleEditorElement);
  • parameters = string.Concat("?TypeName=MyNamespace.Products.Model.ProductItem&Title=Products",
                    "&BackLabelText=", Res.Get<ProductsResources>().BackToItems,
                    "&ItemsName=", "Products");

    Using the above appears to work as expected. I just typed the fullyqualified name for the item
  • question, after i adding the custom properties, when i try to edit the product it throws an error in Copy Method in  ProductManagers, in line
    this.Provider.CopyContent(source, destination)
    
      it said Error executing query: Telerik.OpenAccess.RT.sql.SQLException: Invalid column name 'customColumn'. Statement(s) could not be prepared. do i have to declare the custom column in model too?
  • Hi Augus,

    Thank you for joining the conversation.

    We have identified that this is an issue with Sitefinity and dynamic fields for custom modules, when the fields are added through the UI. The problem is that Sitefinity is not able to properly update the metadata for your custom type. This issue has been resolved for the upcoming release of Stiefintiy 4.1 (due this Wednesday).

    The current workaround is when you add the custom field from the UI you have to open up your database and go to table sf_schema_versions. Then find the row for your module assembly and change the value of meta_data_changed column from 0 to 1. Then restart your website. This will tell Sitefinity that it has to update the metadata of your module and introduce the new field.

    All the best,
    Radoslav Georgiev
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
  • yepp that's works fine thank you Georgiev :)

    another question tough, why is it every time after editing the product, after saving, there's always an exception : "You are trying to access item that no longer exists. The most probable reason is that it has been deleted by another user."
    nothing affected tough, so the backend will still run smoothly. just my curiosity.