FROM Date and Time should not be greater than TO Date and Time using JavaScript

 var flagDropOffFromdat = true;

function dropOffFromdate(executionContext) {

    var formContext = executionContext.getFormContext();

    var dropoffFrom = formContext.getAttribute(" apy_dropoffdatetime").getValue();

    if (dropoffFrom != null && dropoffFrom != undefined && dropoffFrom != "") {

        if (formContext.ui.getFormType() === 1 && flagDropOffFromdat === true) {

            //setTimeout(function () {

            var nowUtc = new Date(dropoffFrom.getFullYear(), dropoffFrom.getMonth(), dropoffFrom.getDate(), 0, 0, 0);

            formContext.getAttribute(" apy_dropoffdatetime").setValue(nowUtc);

            formContext.getAttribute(" apy_dropoffdatetimeto").setValue(nowUtc);

            //}, 1000);     

            flagDropOffFromdat = false;

        } else {

            var dropofFromDate = new Date(dropoffFrom);

            dropofFromDate.setMinutes(dropofFromDate.getMinutes());

            formContext.getAttribute(" apy_dropoffdatetimeto").setValue(dropofFromDate);

        }

    }

}

function pickUpTodate(executionContext) {

    var formContext = executionContext.getFormContext();

    var pickupFrom = formContext.getAttribute(" apy_pickupdatetime").getValue();

    var pickupTo = formContext.getAttribute(" apy_pickupdatetimeto").getValue();

    if (pickupFrom != null && pickupFrom != undefined && pickupFrom != "") {

        var pichupFromDateOnly = pickupFrom.getFullYear() + '-' + (pickupFrom.getMonth() + 1) + '-' + pickupFrom.getDate();

        var pichupToDateOnly = null;

        if (pickupTo != null && pickupTo != undefined && pickupTo != "") {

            pichupToDateOnly = pickupTo.getFullYear() + '-' + (pickupTo.getMonth() + 1) + '-' + pickupTo.getDate();

        }

        var pickupFromDate = null;

        if (formContext.getAttribute(" apy_pickupdatetimeoption") != null && formContext.getAttribute(" apy_pickupdatetimeoption") != undefined && formContext.getAttribute(" apy_pickupdatetimeoption") != "") {

            var pickupDateTimeOption = formContext.getAttribute(" apy_pickupdatetimeoption").getValue();

            if (pickupDateTimeOption === 126210003) {

                if (pickupFrom > pickupTo) {

                    pickupFromDate = new Date(pickupFrom);

                    pickupFromDate.setMinutes(pickupFromDate.getMinutes());

                    setTimeout(function () {

                        alert("PickUp Date&Time From should be less than PickUp Date&Time To");

                        formContext.getAttribute(" apy_pickupdatetimeto").setValue(pickupFromDate);

                    }, 1000);

                }

            } else {

                if (pichupFromDateOnly == pichupToDateOnly) {

                    if (pickupFrom > pickupTo) {

                        pickupFromDate = new Date(pickupFrom);

                        pickupFromDate.setMinutes(pickupFromDate.getMinutes());

                        setTimeout(function () {

                            alert("PickUp Date&Time From should be less than PickUp Date&Time To");

                            formContext.getAttribute(" apy_pickupdatetimeto").setValue(pickupFromDate);

                        }, 1000);

                    }

                } else {

                    pickupFromDate = new Date(pickupFrom);

                    pickupFromDate.setMinutes(pickupFromDate.getMinutes());

                    setTimeout(function () {

                        alert("PickUp Date&Time From, PickUp Date&Time To should have equal Date and Time should be Greater");

                        formContext.getAttribute(" apy_pickupdatetimeto").setValue(pickupFromDate);

                    }, 1000);

                }

            }

        } else if (formContext.data.entity.getEntityName() === "salesorder") {

            if (pichupFromDateOnly == pichupToDateOnly) {

                if (pickupFrom > pickupTo) {

                    //pickupFromDate = new Date(pickupFrom);

                    //pickupFromDate.setMinutes(pickupFromDate.getMinutes());

                    setTimeout(function () {

                        alert("PickUp Date&Time From should be less than PickUp Date&Time To");

                        //formContext.getAttribute(" apy_pickupdatetimeto").setValue(pickupFromDate);

                        var nowUtc = new Date(pickupFrom.getFullYear(), pickupFrom.getMonth(), pickupFrom.getDate(), 0, 0, 0);

                        formContext.getAttribute(" apy_pickupdatetimeto").setValue(nowUtc);

                    }, 1000);

                }

            } else {

                //pickupFromDate = new Date(pickupFrom);

                //pickupFromDate.setMinutes(pickupFromDate.getMinutes());

                setTimeout(function () {

                    alert("PickUp Date&Time From, PickUp Date&Time To should have equal Date and Time should be Greater");

                    //formContext.getAttribute(" apy_pickupdatetimeto").setValue(pickupFromDate);

                    var nowUtc = new Date(pickupFrom.getFullYear(), pickupFrom.getMonth(), pickupFrom.getDate(), 0, 0, 0);

                    formContext.getAttribute(" apy_pickupdatetimeto").setValue(nowUtc);

                }, 1000);

            }

            //var nowUtc = new Date(pickupTo.getFullYear(), pickupTo.getMonth(), pickupTo.getDate(), 0, 0, 0);

            //formContext.getAttribute(" apy_pickupdatetimeto").setValue(nowUtc);

        }

    } else {

        var nowUtc = null;

        if (pickupTo != null && pickupTo != undefined && pickupTo != "") {

            nowUtc = new Date(pickupTo.getFullYear(), pickupTo.getMonth(), pickupTo.getDate(), 0, 0, 0);

        }

        formContext.getAttribute(" apy_pickupdatetimeto").setValue(nowUtc);

    }

}

Comments

Popular posts from this blog

Meta Data Using WebApiRequest

Sample CRUD Operations Using C# in MSCRM

Basic Plugin Code in D365 using C#