CRM Script Help - Date Fields RRS feed

  • Question

  • Order form has two fields, Ship Date (datefield) and Lead Time (number field in days). 

    When a ship date is entered, it should be greater than the current date + the lead time. alert user if not, and do not allow save of record.

    * There is one exception to the rule though: If the approved for rush field and approved by field is filled out the alert is not necessary and record can be saved. 

    ++ It would be a plus if this could actually not account for weekend days. But not mandatory

    function checkLeadTime
    var shipDate = Xrm.Page.getAttribute("requestdeliveryby").getValue();
    var leadTime = Xrm.Page.getAttribute("orbus_leadtime").getValue();
    var leadTimeDate = Xrm.Page.getAttribute("orbus_leadtimedate").getValue():

    if(leadTime != NULL)

    var approvedRushProduction = xrm.getAttribute("orbus_projectapprovedrush").getValue();
    var approvedBy = Xrm.Page.getAttribute("orbus_approvedbyid").getValue();
    var currentTime = new Date();
    var newDate = currentTime.setDays(currentTime.getDays + leadTime);

     if(approvedRushProduction == 0 && approvedBy == NULL)
     if ( newDate < shipDate)
        alert("Sorry, Ship Date is less than lead time!");
        alert("Current Time = " + newDate);

    Friday, October 31, 2014 1:35 PM

All replies

  • I can't work out from your post what help you require. Does the code throw an error (if so, what ?), or does it not return the results you expect ?

    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    Friday, October 31, 2014 2:48 PM
  • No error, it's just not working properly. I do not think my calculation for current date and lead time is working properly.
    Friday, October 31, 2014 2:49 PM