Skip to main content

Date Filter using X++ AX 2012 and D365 F&O

One of the basic functionality that developer uses while using date filters. So here we will be using a helper funtion that will be catering all the conditions that has been linked with Date filter.


Scenario : Here we are using the date set on DimensionAttributeValue to check its validity/Activity

 public boolean validate()
    {
        DimensionAttributeValue dimensionAttributeValue;

        boolean ret = super();

        if (ret && this.DimensionAttributeValue)
        {
            dimensionAttributeValue = DimensionAttributeValue::find(this.DimensionAttributeValue);
        }

        if (dimensionAttributeValue)
        {
            if (dimensionAttributeValue.ActiveFrom != dateNull()
                && (this.ActiveFrom < dimensionAttributeValue.ActiveFrom || this.ActiveFrom == dateNull()))
            {
                // The Active from date for the legal entity cannot be earlier than the shared Active from date.
                ret = checkFailed("@SYS319014");
            }
            else if (dimensionAttributeValue.ActiveTo != dateNull()
                && (this.ActiveTo > dimensionAttributeValue.ActiveTo || this.ActiveTo == dateNull()))
            {
                // The Active to date for the legal entity cannot be later than the shared Active to date.
                ret = checkFailed("@SYS319019");
            }
            else if (this.ActiveFrom != dateNull() && this.ActiveTo != dateNull() && this.ActiveFrom > this.ActiveTo)
            {
                // The Active from date must be greater than the Active to date.
                ret = checkFailed("@SYS317906");
            }
        }

        return ret;
    }

Comments