2012-05-04 17 views
0

すべて、javascriptを使用して開始および終了フィールドの日付に基づいてフィールドに整数を設定します。私はCRMのJavaScriptで週の曜日を見つけるための正しい構文が何であるかもわかりません。ここまでは私のコードです。Microsoft Dynamics CRM 2011の2つの日付間の営業日数を確認

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); 

} 
+0

可能な重複:http://stackoverflow.com/a/543152/684271 –

答えて

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ベースの表現を返します。あなたは2つの日付の間の日数を計算したい場合は 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); 

} 
+0

私に曜日を伝えるに適しています。今は、日付の間に何日あるかを知る必要があります。 CRM JSで日々の日数を加算または減算できますか?助けてくれてありがとう –

+0

私は2つの日付の間の日数の計算も反映するように私の答えを改訂しました。 –

+0

計算では、2つの日付間の日数を教えてくれません。私は1の出力を得ています。私は助けに感謝します。 –

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); 
} 
+2

銀行休業日やその他の休業日は考慮されておらず、週末が休業日である国も考慮されません。 – glosrob

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; 
} 
関連する問題