Dynamics CRM中的定期约会

时间:2010-03-25 17:29:25

标签: javascript dynamics-crm

看起来动态不允许重复约会。我找到了tutorial重复的服务活动,但我并没有真正遵循它发送SOAP对象的部分。如果有人可以提供帮助,我会很感激

2 个答案:

答案 0 :(得分:1)

这可以通过工作流程完成,通过在特定时间间隔或特定条件下创建活动...... CRM本身没有定期约会。

另一种解决方法可能是通过Outlook客户端安排约会,并将客户端与CRM同步,但我没有测试此解决方案。

答案 1 :(得分:0)

可以在不使用工作流的情况下在MS CRM 4.0中创建重新约会约会。

我已经完成了一个用于创建reccuring服务活动的实现。我在服务活动实体中添加了两个新字段。 请阅读以下详细实施:

实体名称:serviceappointment

添加两个新字段

新领域1

字段标签:重复频率 字段名称:new_recurringactivity 要求等级:无约束 Field TYpe:选项列表 字段值:

1 - 每日 2 - 每周 3 - 每两周一次 4 - 每月 5 - 双月刊 6 - 季度 7 - 半年 8年 -

New Field 2

字段标签:重复结束日期 字段名称:new_recurringenddate 字段类型:日期时间 字段格式:仅限日期 要求等级:无约束

新字段的用途

字段名称:new_recurringactivity 目的:此字段将接受来自用户的重复频率。

字段名称:new_recurringenddate 目的:此字段将接受用户的日期。它不会在日期之后创建任何活动。否则它会无限循环。

CODE SNIPPET 1

// Add this code snippet to the OnLoad event of the Service Activity Form

// Lock the recurring Service Activiy fields once activities have been created
if (crmForm.all.new_recurringactivity.DataValue)
{
crmForm.all.new_recurringactivity.disabled = true;
crmForm.all.new_recurringenddate.disabled = true;
}

CODE SNIPPET 2

//将此代码段添加到服务活动的OnSave事件

// Function to format a date to the UTC format required by web services
function DateToUTCFormat(inputDate)
{
var date = inputDate.getDate();
var month = inputDate.getMonth()+1;
var year = inputDate.getYear();
var hours = inputDate.getHours();
var minutes = inputDate.getMinutes();
var ampm = " AM";
if (hours > 11)
    {
    ampm = " PM";
    hours = hours - 12;
    }
if (hours == 0)
    {hours = 12;}
if (minutes < 10)
    {var time = hours.toString() + ":0" + minutes.toString() + ":00" + ampm;}
else
    {var time = hours.toString() + ":" + minutes.toString() + ":00" + ampm;}
var UTCDate = month.toString() + "/" + date.toString() + "/" + year.toString() + " " + time;
return UTCDate;
}


if (crmForm.all.new_recurringactivity.disabled == false && crmForm.all.new_recurringactivity.DataValue && crmForm.all.new_recurringactivity.DataValue)

{
var interval = 0;
switch (parseInt(crmForm.all.new_recurringactivity.DataValue)) 
{
case 1:   // Daily (Please check the value you are getting from the CRM Form)
 interval = 1;
 break;

case 2: // weekly
 interval = 7;
 break;

case 3: // Fortnightly
 interval = 14;
 break;

case 4: // Monthly
 interval = 30;
 break;

case 5: // Bi-Monthly
 interval = 60;
 break;

case 6: // Quarterly
 interval = 90;
 break;

case 7: // Half Yearly
 interval = 180;
 break;

case 8: // Yearly
 interval = 365;
 break;

}

var recurringEnd = crmForm.all.new_recurringenddate.DataValue;
recurringEnd.setDate(recurringEnd.getDate()+1);
var activityStart = crmForm.all.scheduledstart.DataValue;
var activityEnd = crmForm.all.scheduledend.DataValue;

// Set the first reccuring appointment as per the recurring frequency opted by the user

activityStart.setDate(activityStart.getDate()+interval);
activityEnd.setDate(activityEnd.getDate()+interval);

// Prepare values for the new Service Activity

var subject = crmForm.all.subject.DataValue;
var regardingId = crmForm.all.regardingobjectid.DataValue[0].id;
var customerId = crmForm.all.customers.DataValue[0].id;
var serviceid = crmForm.all.serviceid.DataValue[0].id;
var resourceId = crmForm.all.resources.DataValue[0].id;
var ownerId = crmForm.all.ownerid.DataValue[0].id;
var new_recurringactivity = crmForm.all.new_recurringactivity.DataValue;

// Loop for the number of recurring Service Activities
while (activityStart < recurringEnd)
    {    
    // Prepare the SOAP message.
    var startUTC = DateToUTCFormat(activityStart);
    var endUTC = DateToUTCFormat(activityEnd);
   // alert("startUTC: "+startUTC);
    var recurringEndUTC = DateToUTCFormat(recurringEnd);
    var authenticationHeader = GenerateAuthenticationHeader();
    var xml = "<?xml version='1.0' encoding='utf-8'?>" + 
    "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'"+
    " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"+
    " xmlns:xsd='http://www.w3.org/2001/XMLSchema'>"+ 
    authenticationHeader+
    "<soap:Body>"+ 
    "<Create xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>"+ 
    "<entity xsi:type='serviceappointment'>"+
    "<subject>"+subject+"</subject>"+
    "<serviceid>"+serviceid+"</serviceid>"+
    "<ownerid>"+ownerId+"</ownerid>"+
    "<customers>"+
        "<activityparty>"+
            "<partyobjecttypecode>account</partyobjecttypecode>"+
            "<partyid>"+customerId+"</partyid>"+
            "<participationtypemask>11</participationtypemask>"+
        "</activityparty>"+
    "</customers>"+
    "<resources>"+
        "<activityparty>"+
            "<partyobjecttypecode>systemuser</partyobjecttypecode>"+
            "<partyid>"+resourceId+"</partyid>"+
            "<participationtypemask>1</participationtypemask>"+
        "</activityparty>"+
    "</resources>"+
    "<scheduledstart>"+startUTC+"</scheduledstart>"+
    "<scheduledend>"+endUTC+"</scheduledend>"+
    "<new_recurringenddate>"+recurringEndUTC+"</new_recurringenddate>"+
    "<new_recurringactivity>"+new_recurringactivity+"</new_recurringactivity>"+
    "</entity>"+ 
    "</Create>"+ 
    "</soap:Body>"+ 
    "</soap:Envelope>";
    // Prepare the xmlHttpObject and send the request.
    var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
    xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
    xHReq.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/Create");
    xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xHReq.setRequestHeader("Content-Length", xml.length);
    xHReq.send(xml);
    // Capture the result
    var resultXml = xHReq.responseXML;

    // Check for errors.
    var errorCount = resultXml.selectNodes('//error').length;
    if (errorCount != 0)
        {
         var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
         alert(msg);
        }
    // Notify user of Service Activity creation
    else
        {
       // alert("Service Activity created on " + activityStart);
        }
    // Increment the next Service Actvity to be created by as per the recurring frequency opted by the user
    activityStart.setDate(activityStart.getDate()+interval);
    activityEnd.setDate(activityEnd.getDate()+interval);
    }

} // Code block Ends

更多解释

请注意,在上面的代码片段中,我将资源作为用户使用。所以我已经在代码片段中使用了

"<resources>"+
        "<activityparty>"+
            "<partyobjecttypecode>systemuser</partyobjecttypecode>"+
            "<partyid>"+resourceId+"</partyid>"+
            "<participationtypemask>1</participationtypemask>"+
        "</activityparty>"+
    "</resources>"+

如果您正在考虑将设备作为您的资源,请使用

"<partyobjecttypecode>systemuser</partyobjecttypecode>"+

另请注意,如果要接受多个资源,则需要更改“participanttypemask”节点中的值。

因为我期待1个资源所以我将值保持为1。

如果有帮助,请告诉我。

如果您无法正常查看代码,则还可以访问http://social.microsoft.com/forums/en-US/crmdevelopment/thread/3f020e02-cd86-44b2-9cff-36e6cdafc8d8/

此致

Sarbashish Bhattacharjee

相关问题