2012-05-04 2 views
0

모두 저는 시작 및 끝 필드의 날짜를 기준으로 필드에 정수를 설정하는 데 javascript를 사용하려고합니다. 나는 CRM 자바 스크립트로 요일을 찾는 올바른 구문이 무엇인지 잘 모릅니다. 지금까지 제 코드가 있습니다.Microsoft Dynamics CRM 2011에서 두 날짜 사이의 영업일 수 찾기

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 기반 표현을 반환합니다. 당신이 두 날짜 사이의 일 수를 계산하려면 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

두 날짜 사이의 일 수를 계산할 수있는 계산이 여전히 작동하지 않습니다. 나는 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; 
} 
관련 문제