2015年2月11日 星期三

CRM 2011 建立新表單預設日期欄位

CRM 2011 建立新表單預設日期欄位
CRM 2011 DateTime Default Value

JavaScript:
function OnLoad()
{
   if (Xrm.Page.ui.getFormType() == 1) //Create New Form 建立新表單時
   {
      var startdate= Xrm.Page.getAttribute('scheduledstart');
      var today = new Date();
      startdate.setValue(today);
   }
}



/*** Other Sample ***/


JavaScript:
function SetStartEndDate()
{
    var startdate= Xrm.Page.getAttribute('scheduledstart');
    var enddate= Xrm.Page.getAttribute('scheduledend');

    var today = new Date();
    var yesterday= new Date(today);
    var beforeday = new Date();
    yesterday.setDate(today.getDate()- 1);
    beforeday .setDate(yesterday.getDate()- 6);

    startdate.setValue(beforeday);
    enddate.setValue(yesterday);
}
/*** OnChange ***/
function EndDtate_OnChange()
{
    var startdate= Xrm.Page.getAttribute('scheduledstart');
    var enddate= Xrm.Page.getAttribute('scheduledend');

    var yesterday=enddate.getValue();
    var beforeday = new Date();
    beforeday .setDate(yesterday.getDate()- 6);

    startdate.setValue(beforeday);
}
/*** Sample ***/
function SetDefaultDateTimeValue(attributeName, hour, minute)
{
    // FORM_TYPE_CREATE = 1
    if (Xrm.Page.ui.getFormType() == 1)
    {
        var attribute = Xrm.Page.getAttribute(attributeName);

       if (attribute.getValue() == null)
        {
           var today = new Date();
           var yesterday= new Date(today);
           yesterday.setDate(today.getDate()- 1);
           attribute.setValue(yesterday);
       }

        //指定日期+小時+分鐘
        attribute.setValue(attribute.getValue().setHours(hour, minute, 0));
    }
}

沒有留言:

張貼留言