I am trying to get the date string value(mm/dd/yyyy)from a custom date and time field and set the returned value back into the custom field. I found this script and modified it but it does not seem to work. When I step through the code it breaks on var year = startDate.getFullYear() + ""; Any ideas what I am doing wrong? Thanks.
    function ConcatChainsAuth() {
    var startDate = Xrm.Page.getAttribute("new_dateauthorized").getValue();
    if (startDate != null) {
        var year = startDate.getFullYear() + "";
        var month = (startDate.getMonth() + 1) + "";
        var day = startDate.getDate() + "";
        var dateFormat = month + "-" + day + "-" + year;
      Xrm.Page.getAttribute("new_dateauthorized").setValue(dateFormat);
    }
    var lookupObject = Xrm.Page.getAttribute("new_chain");
    if (lookupObject != null) {
        var lookUpObjectValue = lookupObject.getValue();
        if ((lookUpObjectValue != null)) {
            var Chain = lookUpObjectValue[0].name;
        }
    }
    var lookupObject = Xrm.Page.getAttribute("new_package");
    if (lookupObject != null) {
        var lookUpObjectValue = lookupObject.getValue();
        if ((lookUpObjectValue != null)) {
            var Package = lookUpObjectValue[0].name;
        }
    }
    var concatedField = Chain + "-" + Package + "-" + dateFormat;
    Xrm.Page.getAttribute("new_name").setValue(concatedField);
    Xrm.Page.data.entity.save();
}
 
     
    