Monday, July 1, 2024

GET the corect date and timezone of the client in Dynamics 365 for Finance and Operations

Many a time we get a requirement to fetch exact data and time from a user , in that case we can use system inbuilt function from DateTimeUtility

Below is such a scenario we faced from checking the date must not be lesser than today. This code fit in the best way.


 public boolean validateField(FieldId _fieldIdToCheck)

    {

        boolean ret;

    

        ret = super(_fieldIdToCheck);


        switch(_fieldIdToCheck)

        {

            case fieldNum(ConVMSVehicleTablePhase2, AcquiredDate):

                Timezone clientTimeZone = DateTimeUtil::getClientMachineTimeZone();

                TransDate today = DateTimeUtil::getSystemDate(clientTimeZone);

                if(this.AcquiredDate < today)

                {   

                    ret = checkFailed("@ConVMS:AcqDateMustBeTodayOrLater");

                }

        }

    

        return ret;

    }

No comments:

Post a Comment

How to add a number sequence in a new table in Dynamics 365 for Finance and Operations?

 In this blog , we will create a new number sequence in D365 Finance and Operations form.  And this blog will contain below steps for the us...