hljs.configure({cssSelector: "code"}); hljs.highlightAll();

Friday, July 26, 2024

How to add financial dimension values validation on Purchase order level


By default, when selecting a value for BusinessUnit or Department in Microsoft Dynamics AX, the system checks whether the specified value exists at the source level. If the value is available, it allows the change. However, if the dimension value is suspended or not activated, the system still permits the record to be saved, only issuing a warning message.

My requirement is to ensure that if the department or BusinessUnit is suspended or has an "active to" date that is earlier than the transaction date, the system should not allow the record to move forward. Instead, it should prevent the action and display an error message. To achieve this i have written below code

[ExtensionOf(formDataSourceStr(PurchTable, PurchTable))]
public final class PurchTableDS_Extension
{
    int active()
    {
        PurchTable purchtable = this.cursor();
        DimensionEntryControl DimensionEntryControlHeader;
 	DimensionEntryControlHeader = this.formRun().design().
			controlName(formControlStr(PurchTable, DimensionEntryControlHeader));
        int ret = next active();
        if (purchTable.AccountingDate)
        {
            DimensionEntryControlHeader.parmNonActiveValueErrorTolerance(ErrorTolerance::Error);// This is 
            DimensionEntryControlHeader.parmActiveValueFilterDate(purchTable.AccountingDate);
        }
        return ret;
    }
    void create(boolean append)
    {
        next create(append);
        PurchTable purchtable = this.cursor();
        DimensionEntryControl DimensionEntryControlHeader;
 	DimensionEntryControlHeader= this.formRun().design().
                           controlName(formControlStr(PurchTable, DimensionEntryControlHeader));
        if (purchTable.AccountingDate)
        {
            DimensionEntryControlHeader.parmNonActiveValueErrorTolerance(ErrorTolerance::Error);
            DimensionEntryControlHeader.parmActiveValueFilterDate(purchTable.AccountingDate);
        }
    }
}
DimensionEntryControl is a dimension control that extends the FormContainerControl class.

The parmNonActiveValueErrorTolerance() method determines whether to throw an error or a warning. It accepts the following values:

ErrorTolerance is an enum that includes Error, Warning, and Accept. By default (OOB), the value is set to Warning.
The parmActiveValueFilterDate() method accepts a date value to check whether a dimension is active or not. This date value helps determine if the dimension is valid based on its "active from" and "active to" dates defined in the Dimension Values Master form.

Thanks for reading!!

No comments:

Post a Comment