I added a new field in the Document management parameters form, but this new field cannot save the changes I made correctly

Hello everyone,

I have added some new features to the original attachment page of Dynamics 365, and now I want to add a Check Box in the Document management parameters form so that users can choose whether to enable these new features.

I don’t know how to implement this feature, so I created the “LDCustomizationParameters” table based on the “DocuSharedParameters” table and added it as the data source for the Document management parameters form.

In the LDCustomizationParameter table, I added an enumeration type field called “EnablingContractManagementFeature” to record the choices made by the user. When the value of “EnablingContractManagementFeature” is “No”, the new feature will be in an unavailable state.

But when I tested this feature, I found that clicking Check Box in the form did not correctly change the value of the EnablingContractManagementFeature field.

This causes the value of the “EnablingContractManagementFeature” field to remain “No” and the new feature to remain in an unenabled state.

Perhaps I missed something in my work? Please help me.

Finally, there is the code for the LDCustomizationParameters table, which I copied from the DocuSharedParameters table.

public class LDCustomizationParameters extends common
{
    #OCCRetryCount

    /// <summary>
    /// If no record exists in table, the method adds a default record.
    /// </summary>
    public LDCustomizationParameters ensureSingleRecordExists()
    {
        try
        {
            select firstonly this;

            if (!this.RecId)
            {
                this.EnableContractManagementFeature = NoYes::No;
                ttsbegin;
                this.insert();
                ttscommit;
            }
            return this;
        }
        #StandardRetryCatchBlock
    }

    /// <summary>
    /// Checks if the contract management feature is enabled.
    /// </summary>
    /// <returns>
    /// True if the contract management feature is enabled. False if the contract
    /// management feature is disabled.
    /// </returns>
    public boolean isContractManagementFeatureEnabled()
    {
        return this.EnableContractManagementFeature;
    }

    /// <summary>
    /// Checks if the contract management feature is enabled.
    /// </summary>
    /// <returns>
    /// True if the contract management feature is enabled. False if the contract
    /// management feature is disabled.
    /// </returns>
    public static boolean isContractManagementEnabled()
    {
        return LDCustomizationParameters::find().isContractManagementFeatureEnabled();
    }

    /// <summary>
    /// Returns a singleton record.
    /// </summary>
    /// <returns>DocuSharedParameters record</returns>
    public static LDCustomizationParameters find(boolean _forUpdate = false)
    {
        if (!_forupdate && LDCustomizationParametersCacheItem::getLDCustomizationParameters())
        {
            return LDCustomizationParametersCacheItem::getLDCustomizationParameters();
        }
        return LDCustomizationParameters::findInternal(_forupdate);
    }

    /// <summary>
    /// Finds the singleton record in the table.
    /// </summary>
    /// <param name="_forupdate">
    /// A boolean value that indicates whether to read the selected record for
    /// update; optional.
    /// </param>
    /// <returns>The singleton record in the table.</returns>
    /// <remarks>The method makes sure that a record is returned.</remarks>
    internal static LDCustomizationParameters findInternal(boolean _forupdate = false)
    {
        LDCustomizationParameters ldCustomizationParameters;

        ldCustomizationParameters.selectForUpdate(_forupdate);

        select firstonly ldCustomizationParameters;

        if(!ldCustomizationParameters)
        {
            return ldCustomizationParameters.ensureSingleRecordExists();
        }

        LDCustomizationParametersCacheItem::setLDCustomizationParameters(ldCustomizationParameters);
        return ldCustomizationParameters;
    }

    public void insert()
    {
        super();
        LDCustomizationParametersCacheItem::setLDCustomizationParameters(this);
    }

    public void delete()
    {
        super();
        LDCustomizationParametersCacheItem::setLDCustomizationParameters(null);
    }

    public void update()
    {
        super();
        // When I modified and saved the value of Check Box, ↓this↓ Info did not appear, so I believe that the update method was not called
        Info(strFmt("enable contract management feature is %1", this.EnableContractManagementFeature));
        LDCustomizationParametersCacheItem::setLDCustomizationParameters(this);
    }

}

LDCustomizationParametersCacheItem Class↓

internal class LDCustomizationParametersCacheItem
{
    internal static LDCustomizationParameters cachedLDCustomizationParameters;

    public static LDCustomizationParameters getLDCustomizationParameters()
    {
        return LDCustomizationParametersCacheItem::cachedLDCustomizationParameters;
    }

    public static void setLDCustomizationParameters(LDCustomizationParameters ldCustomizationParameters)
    {
        LDCustomizationParametersCacheItem::cachedLDCustomizationParameters = ldCustomizationParameters;
    }

}

Why don’t you simply create an extension of DocuSharedParameters table and add the field there?

Hello @MartinDrab
I want different companies to have different settings, but the DocuSharedParameters table does not have “Save Data Per Company” enabled.
I hope the DocuSharedParameters table will maintain its original settings.

The Save button saves DocuSharedParameters record. If your data source isn’t joined to DocuSharedParameters, then it’s not saved automatically when DocuSharedParameters is saved. You can changed that by, for example, creating an extension of DocuSharedParameters data source, extend its write() method and save your data source from there.

It works, but I did not extend the write() method of the DocuSharedParameters data source. After testing, I found that the write() method of the DocuSharedParameters data source was not called when I clicked the save button. Therefore, I save my data source in the modified() method of the form control.

So the reason for the problem is that in the Document management parameters form, the save button only takes effect on existing data sources and their extensions, and not on newly extended data sources, right?

No, it’s not about extensions. You can add a joined data source through an extension that will be saved together with the parent data source. But if you save one data source, it doesn’t mean that it’ll automatically save another, completely independent data source.

I understand, thank you for your explanation. I have never developed forms with multiple data sources before, which makes me overlook many important things in my work. :joy: