Default Value for Inherited Field?

Adam Steffes asked on July 21, 2015 19:33

I have several product document types sharing a custom field "tax classification" inherited from "product base".

What options are available for setting the default value of a field inherited from a base document type?

My thoughts:

  1. Remove inheritance and create the same field independently on each document type
  2. Create a custom form control that can create a filtered list of options based on the context (the document type) being created.

I don't know whether #2 is a real possibility or not.

Are there other clever options available to get around this restriction?

Correct Answer

Roman Hutnyk answered on July 21, 2015 19:57

Recently I had the same problem, but customer also wanted to be able to configure this on his own.

So I've created table for mapping of default values to a page type - so that covered second part of the request. For populating those values I've implemented custom macro and entered it as default value to the base page type. Custom macro looks like this:

[MacroMethod(typeof(string), "Get default value for the given field.", 1)]
    [MacroMethodParam(0, "ColumnName", typeof(string), "Column name")]
    public static object GetDefaultValue(EvaluationContext context, params object[] parameters)
        string columnName = ValidationHelper.GetString(parameters[0], String.Empty);
        if (!string.IsNullOrEmpty(columnName) && DocumentContext.EditedDocument != null)
            DataSet dataSet = CacheHelper.Cache(cs => GetDocumentDefaultFields(DocumentContext.EditedDocument.ClassName, cs),
                new CacheSettings(60, string.Format("{0}|{1}", "documenttypedefaultfield", DocumentContext.EditedDocument.ClassName)));

            if (!DataHelper.DataSourceIsEmpty(dataSet))
                return dataSet.Tables[0].Rows[0][columnName];
        return null;
0 votesVote for this answer Unmark Correct answer

   Please, sign in to be able to submit a new answer.