在CRM 2013中,使用OData端点和javascript将多个资源与服务预约实体关联

在CRM 2013中,使用OData端点和javascript将多个资源与服务预约实体关联,javascript,dynamics-crm,dynamics-crm-2013,Javascript,Dynamics Crm,Dynamics Crm 2013,我的目标是创建与多个资源关联的服务预约记录 为此,我遵循了这一原则 当我尝试为一个特定的服务约会关联多个资源时,问题就出现了,CRM服务器将只存储最后一条one1记录。下面演示了我的代码: //attendees =[... array of resource ids] var serviceAppointment = { ScheduledStart: new Date("12/22/2014 4:53 PM"), ScheduledEnd: new Date(

我的目标是创建与多个资源关联的服务预约记录

为此,我遵循了这一原则

当我尝试为一个特定的服务约会关联多个资源时,问题就出现了,CRM服务器将只存储最后一条one1记录。下面演示了我的代码:

//attendees =[... array of resource ids]
var serviceAppointment = {
        ScheduledStart: new Date("12/22/2014 4:53 PM"),
        ScheduledEnd: new Date("12/22/2014 5:53 PM"),
        Subject: "test service",
        ServiceId:
        {
            //// hardcoded id for simplicity
            Id: "6f795012-ca55-e411-aa38-00155d0a0948",
            LogicalName: "service"
        }
    };
    SDK.JQuery.createRecord(serviceAppointment,"ServiceAppointment"
    ,function(sa){
        for(var i=0;i<attendees.length;i++)
        {
            var activityParty = {
                PartyId:
                {
                    Id: attendees[i],
                    LogicalName: "systemuser",
                },
                ActivityId: 
                {
                    Id: sa.ActivityId,
                    LogicalName: "serviceappointment",
                },
                ParticipationTypeMask:
                {   
                    //See http://msdn.microsoft.com/en-us/library/gg328549.aspx
                    //10 is for resource
                    Value: 10
                }
            };
            SDK.JQuery.createRecord(activityParty,"ActivityParty", function(ap){debugger;},errorHandler);
        }
    }
    ,errorHandler);
就我调试代码而言,create记录毫无例外地正确执行。我相信我的代码中缺少了一个配置标志,CRM考虑的是一对一的关联,而不是一对多的关联。
有什么线索吗

我可以通过首先传递服务预约记录中的一组当事人来解决这个问题,而不是在最后逐个插入他们。以下是有效的代码:

    var parties =[];
    for(var i=0;i<  e.event.attendees.length;i++)
    {           
        var activityParty = {
            PartyId:
            {
                Id: e.event.attendees[i],
                LogicalName: "systemuser",
            },
            ParticipationTypeMask:
            {   
                //See http://msdn.microsoft.com/en-us/library/gg328549.aspx
                //10 is for resource
                Value: 10
            }
        }
        parties.push(activityParty);
    }
    var serviceAppointment = {
        ScheduledStart: e.event.start,
        ScheduledEnd: e.event.end,
        Subject: e.event.title,
        ServiceId:
        {
            Id: "6f795012-ca55-e411-aa38-00155d0a0948",
            LogicalName: "service"
        },
        serviceappointment_activity_parties: parties,
    };


    SDK.JQuery.createRecord(serviceAppointment,"ServiceAppointment"
    ,function(sa){
        debugger;
        e.event.ActivityId = serviceAppointmentActivityId = sa.ActivityId;
    }
    ,errorHandler);
    }
希望它能帮助别人