1

所有,我正在尝试使用 javascript 根据开始和结束字段中的日期将整数设置为字段。我什至不确定使用 CRM javascript 查找星期几的正确语法是什么。到目前为止,这是我的代码。

function netbdays_change() {

    var startday = Xrm.Page.getAttribute("new_quotestart").getValue();
    var endday = Xrm.Page.getAttribute("new_quoteend").getValue();

    cycletime = endday - startday;

    Xrm.Page.getAttribute("new_setcycletime").setValue(cycletime);

}
4

3 回答 3

3

试试这个:

function netbdays_change() {

    var startday = Xrm.Page.getAttribute("new_quotestart").getValue().getDay();
    var endday = Xrm.Page.getAttribute("new_quoteend").getValue().getDay();

    cycletime = endday - startday;

    Xrm.Page.getAttribute("new_setcycletime").setValue(cycletime);

}

getDay() 返回一个基于 0 的星期几的表示。 http://www.w3schools.com/jsref/jsref_getday.asp

如果你想计算两个日期之间的天数,试试这个:

function netbdays_change() {

    var startday = Xrm.Page.getAttribute("new_quotestart").getValue();
    var endday = Xrm.Page.getAttribute("new_quoteend").getValue();

    cycletime = Math.abs(endday - startday)

    Xrm.Page.getAttribute("new_setcycletime").setValue(cycletime / 86400000);

}
于 2012-05-04T18:32:49.393 回答
0

我终于想出了解决方案:随意使用每个人。:)

function netbdays_change() {
    var startdays = Xrm.Page.getAttribute("new_dateqaassigned").getValue();
    var enddays = Xrm.Page.getAttribute("new_quotecomplete").getValue();

    var cycletime = Math.abs(enddays - startdays) / 86400000; // This first part now works

    startday = Xrm.Page.getAttribute("new_dateqaassigned").getValue().getDay();
    endday = Xrm.Page.getAttribute("new_quotecomplete").getValue().getDay();

    var x = startday; // day of the week
    var y = 0; // number of business days for output
    var z = 0; // augment up to the total number of days

    while (x <= 7 && z <= cycletime) {
        if (x > 0 && x < 6) {
            y++;
        }
        x++;
        z++;
    }
    x = 0;
    while (x <= 7 && z <= cycletime) {
        if (x > 0 && x < 6) {
        y++;
    }
        x++;
        z++;
        if (x == 6) {
            x = 0;
        }
    }
    Xrm.Page.getAttribute("new_quotetotalcycletime").setValue(y);
}
于 2012-05-05T04:11:25.423 回答
0

这是我的代码:

function GetBusinessDays(startDate, endDate)
{
    if (startDate != null && endDate != null)
    {
        var cycletime = (Math.abs(endDate - startDate) / 86400000) + 1;
        var startday = startDate.getDay();
        var x = startday; // day of the week
        var y = 0; // number of business days for output
        var z = 0; // augment up to the total number of days

        while (z < cycletime) {
            if (x > 0 && x < 6) 
            {
                y++;
            }
            x++;
            z++;
            if (x > 6)
            {
                x = 0;
            }
        }

        return y;
    }
    return null;
}
于 2013-09-18T05:41:57.023 回答