2013-12-12 61 views
2

如何清除日期字段?crm 2011 javascript設置日期字段爲空

下面的代碼似乎並沒有工作:

if (Xrm.Page.getAttribute("new_boolfield1").getValue() != null) { 

     switch(Xrm.Page.getAttribute("new_boolfield1").getValue()) { 

     case false: 

      Xrm.Page.getAttribute("new_datefield1").setValue(null); // this doesn't work 
      Xrm.Page.getAttribute("new_datefield1").setValue(); // this doesn't work either 

     case true: 

      Xrm.Page.getAttribute("new_datefield1").setValue(new Date()); 
     } 
    } 

回答

3
Xrm.Page.getAttribute('new_datefield1').setValue(); 

應該工作。請確保你沒有設置你的日期字段其他地方,並確保把break語句

http://crmbusiness.wordpress.com/2012/05/17/crm-2011-javascript-to-set-the-current-date-and-time/

**編輯**這是你的case語句

var b = false; 
switch(b) { 
    case false: 
    console.log("false"); 
    case true: 
    console.log("true"); 
} 

沒有break語句這將打印出「假真」

var b = false; 
switch(b) { 
    case false: 
    console.log("false"); 
    break; 
    case true: 
    console.log("true"); 
    break; // <- not really required but good practise 
} 
+0

你是對的,打破了缺失 –

1

清除CRM 2011中字段的正確方法是將其值設置爲null

Xrm.Page.getAttribute("new_datefield1").setValue(null); 

如果你的領域仍未清除,可能是出於兩個原因:

  1. 你設定日期別的地方(如jasonscript 建議)

  2. new_boolfield1不一個布爾字段(CRM中的two options),但一個選項集

可以容易地測試這些條件下,開關之外的第一校驗,第二與alertconsole.log

0

null是假,所以這是更清潔

var xrmPage = Xrm.Page; 
var date1 = xrmPage.getAttribute("new_datefield1"); 
var bValid = xrmPage.getAttribute("new_boolfield1").getValue(); 
date1.setValue(bValid ? new Date() : null); 

投票了上述由於答案它也會糾正你的代碼

相關問題