Example #1
0
        /// <inheritdoc />
        public void RemoveField(IWebPartField field)
        {
            var formInfo = new FormInfo(field.WebPart.WebPartProperties);

            formInfo.RemoveFields(x => x.Name == field.Name);

            field.WebPart.WebPartProperties = formInfo.GetXmlDefinition();

            this.SaveFormUpdates(field.WebPart);
        }
    /// <summary>
    /// Copies custom fields from old version of form definition to the new form definition.
    /// </summary>
    /// <param name="oldVersionFi">Old version form definition</param>
    /// <param name="newVersionFi">New version form definition</param>
    /// <param name="overwrite">Indicates whether existing fields should be overwritten. Alternative form fields need to be overwritten due to the combination with upgraded class form.</param>
    private static void CopyCustomFields(FormInfo oldVersionFi, FormInfo newVersionFi, bool overwrite)
    {
        // Remove all system fields from old definition to get only custom fields
        oldVersionFi.RemoveFields(f => f.System);

        // Combine forms so that custom fields from old definition are appended to the new definition
        newVersionFi.CombineWithForm(oldVersionFi, new CombineWithFormSettings
        {
            IncludeCategories     = false,
            RemoveEmptyCategories = true,
            OverwriteExisting     = overwrite
        });
    }
    /// <summary>
    /// Copies custom fields from old version of form definition to the new form definition.
    /// </summary>
    /// <param name="oldVersionFi">Old version form definition</param>
    /// <param name="newVersionFi">New version form definition</param>
    /// <param name="overwrite">Indicates whether existing fields should be overwritten. Alternative form fields need to be overwritten due to the combination with upgraded class form.</param>
    private static void CopyCustomFields(FormInfo oldVersionFi, FormInfo newVersionFi, bool overwrite)
    {
        // Remove all system fields from old definition to get only custom fields
        oldVersionFi.RemoveFields(f => f.System);

        // Combine forms so that custom fields from old definition are appended to the new definition
        newVersionFi.CombineWithForm(oldVersionFi, new CombineWithFormSettings
        {
            IncludeCategories = false,
            RemoveEmptyCategories = true,
            OverwriteExisting = overwrite
        });
    }
    /// <summary>
    /// Copies custom fields from old version of form definition to the new form definition.
    /// </summary>
    /// <param name="oldVersionFi">Old version form definition</param>
    /// <param name="newVersionFi">New version form definition</param>
    /// <param name="overwrite">Indicates whether existing fields should be overwritten. Alternative form fields need to be overwritten due to the combination with upgraded class form.</param>
    /// <param name="isSystemTable">Indicates whether the class is customizable.</param>
    private static void CopyCustomFields(FormInfo oldVersionFi, FormInfo newVersionFi, bool overwrite, bool isSystemTable)
    {
        // Remove all system fields from old definition to get only custom fields
        // Remove all dummy fields from old definition for non-customizable classes (Since v9 is condition f => f.System sufficient because dummy fields created in development mode are system)
        // * Dummy field in alternative forms are not marked as system in version < v9 and should be updated. Without this condition the old version of dummy field was used instead of new one.
        // * Dummy field is not removed from customizable classes due to possible customization.
        oldVersionFi.RemoveFields(f => f.System || (f.IsDummyField && !isSystemTable));

        // Combine forms so that custom fields from old definition are appended to the new definition
        newVersionFi.CombineWithForm(oldVersionFi, new CombineWithFormSettings
        {
            IncludeCategories = false,
            RemoveEmptyCategories = true,
            OverwriteExisting = overwrite
        });
    }