Tuesday, July 11, 2023

How to open CustChangeProposal form for custom field in D365 X++

 My requirement is to add a custom field in Custtable form. 

Add a element in Enable Customer Approval Tab in AR Parameters.

If the element is checked. Then if we modify blocked field in Custtable form ,it should work like standard process i.e., a dialogue form(CustChangeProposal) should be opened containing the old and new values of field.

Field : DaxBlocked (Enum)

Add a element in CustTableChangeProposalField Base Enum :




Create a enum field :

Add Created enum in Following Tables:

1.CustTable
2.CustTableChangeProposal (Add Extra Field as like below)

Add A Group Control in CustChangeProposalForm :

Code :

[ExtensionOf(tableStr(CustTableChangeProposal))]
internal final class DaxCustableChangeProposal_Extension
{
    public void setFlagForChangedField(CustTableChangeProposalField _controlledField)
    {
        next setFlagForChangedField(_controlledField);
        switch (_controlledField)
        {
            case CustTableChangeProposalField::DaxBlocked :
                this.IsChangedDaxBlocked = NoYes::Yes;
                break;
        }
    }
}

..................................................................

[ExtensionOf(formControlStr(CustChangeProposal,DiscardDaxBlocked))]
internal final class DaxCustChangeProposal_Extension
{
    public void clicked()
    {
        FormControl                 callerButton    = any2Object(this) as FormControl;
        FormRun                     formRun         = callerButton.formRun();
        FormDataSource              formDataSource  = formRun.datasource();
        CustTableChangeProposal     custTableChangeProposal = formDataSource.cursor();
        ttsbegin;
        CustTableChangeProposal localRecord = CustTableChangeProposal::findByCustRecId(custTableChangeProposal.CustTable, true);
        localRecord.IsChangedDaxBlocked = NoYes::No;
        localRecord.update();
        ttscommit;
        next clicked();
    }
}

........................................................................

[ExtensionOf(formStr(CustChangeProposal))]
internal final class DaxCustChangeProposalForm_Extension
{
    protected void disableDiscardButtons()
    {
        FormRun formRun = this as FormRun;
        FormControl discardDaxBlocked = formRun.design().controlName(formControlStr(CustChangeProposal, DiscarddaxBlocked)) as FormControl;
        next disableDiscardButtons();
        discardDaxBlocked.enabled(false);
    }
      public void showHideGroups()
    {
        CustTableChangeProposal custTableChangeProposal;
        FormRun formRun = this as FormRun;
        FormDataSource  custTableChangeProposal_ds = formRun.dataSource(1);
        FormGroupControl  DaxBlocked = formRun.design().controlName(formControlStr(CustChangeProposal, DaxBlocked)) as FormGroupControl;
        custTableChangeProposal = custTableChangeProposal_ds.cursor();
        next showHideGroups();
        DaxBlocked.visible(custTableChangeProposal.IsChangedDaxBlocked);
    }
}

..........................................................................................

[ExtensionOf(tableStr(CustTableChangeProposalFieldEnablement))]
internal final class DaxCustTableChangeProposalFieldEnablement_Extension
{
    public static void initializeAll()
    {
        next initializeAll();
        CustTableChangeProposalFieldEnablement::findOrCreate(CustTableChangeProposalField::DaxBlocked);
    }
}

............................................................................

[ExtensionOf(formStr(CustTable))]
internal final class DaxCustTableForm_Extension
{
    public void markChangeProposalFields()
    {
        next markChangeProposalFields();
        if (CustTableChangeProposalFieldEnablement::isEnabledFor(CustTableChangeProposalField::DaxBlocked))
        {
            CustTable_DaxBlocked.label(strFmt(
                "@AccountsReceivable:FieldLabelMarkingInBrackets",
                CustTable_ds.object(fieldNum(CustTable, DaxBlocked)).labelText(),
                "@AccountsReceivable:FieldLabelMarkingRequiresApproval"));
        }
      }
}

................................................................................

[ExtensionOf(formDataFieldStr(CustTable,CustTable,DaxBlocked))]
internal final class DaxCustTableFormDataField_Extension
{
    public void modified()
    {
        FormDataObject formDataObject = any2Object(this) as FormDataObject;
        FormDataSource formDataSource = formDataObject.datasource();
        FormRun formRun = formDataSource.formRun();
        CustTable   custTable = formDataSource.cursor();
        formRun.showCustChangeProposalDialog();
        formRun.modifiedControlledField(
                    fieldNum(CustTable, DaxBlocked),
                    fieldNum(CustTableChangeProposal, DaxBlocked),
                    custTable,
                    CustTableChangeProposalField::DaxBlocked);
        next modified();
    }
}

.................................................................................

Output :

ARParameters:














No comments:

Post a Comment