+1-888-365-2779
Try Now
More in this section

Forums / Sitefinity SDK / Adding Custom Fields Option to Custom Modules

Adding Custom Fields Option to Custom Modules

7 posts, 1 answered
  1. Drew Greenwell
    Drew Greenwell avatar
    66 posts
    Registered:
    11 Feb 2010
    17 Mar 2011
    Link to this post
    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
  2. jocelyn payneau
    jocelyn payneau avatar
    51 posts
    Registered:
    07 Dec 2009
    18 Mar 2011
    Link to this post
    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
    Answered
  3. Drew Greenwell
    Drew Greenwell avatar
    66 posts
    Registered:
    11 Feb 2010
    18 Mar 2011
    Link to this post
    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
    http://localhost:60876/Sitefinity/Services/MetaData/ModuleEditor.svc/custom/?contentType=&skip=0&take=20&filter=

    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);
  4. Drew Greenwell
    Drew Greenwell avatar
    66 posts
    Registered:
    11 Feb 2010
    18 Mar 2011
    Link to this post
    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
  5. Augus
    Augus avatar
    34 posts
    Registered:
    29 Mar 2011
    12 Apr 2011
    Link to this post
    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?
  6. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    12 Apr 2011
    Link to this post
    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 >>

  7. Augus
    Augus avatar
    34 posts
    Registered:
    29 Mar 2011
    12 Apr 2011
    Link to this post
    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.
7 posts, 1 answered