使用CRM 2013中的javascript,使用OData端点将多个资源与服务约会实体相关联

时间:2014-12-22 16:01:36

标签: javascript dynamics-crm dynamics-crm-2013

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

为此,我遵循了this MSDN example

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

//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);

就我调试代码而言,正在正确执行创建记录而没有例外。我相信我在代码中的某个地方错过了配置标记,CRM正在考虑一对一关联而不是一对一关联。 有线索吗?

1 个答案:

答案 0 :(得分:0)

我可以通过首先在服务约会记录中传递一组参与者而不是在最后逐个插入它来解决这个问题。这是有效的代码:

    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);
    }

希望它可以帮助那些人。