1

我正在尝试创建一个服务活动,但它会引发错误,代码如下:

var oDataPath = Xrm.Page.context.getServerUrl() + "/XRMServices/2011/OrganizationData.svc";

    var oDataSetName = "ServiceAppointmentSet";
    var entityTypeCode = "4212"; // Type code of ServiceAppointment
    var subject = 'Test Subject';
    var entityId = Xrm.Page.data.entity.getId();
    var serviceId = "AFE9429-ABCE-E211-877A-000C298A36A7";

    var customactivity = new Object();
    customactivity.Subject = subject;
    customactivity.ActivityTypeCode = entityTypeCode;    

    customactivity.RegardingObjectId =
    {
        Id: entityId,
        LogicalName: "incident",
        Name: subject
    };

    var punchInTime = GetPunchInTime();
    customactivity.ScheduledStart = punchInTime;
    customactivity.ScheduledEnd = punchInTime;


    //---- serviceId


    if (serviceId != null) {
        customactivity.ServiceId =
            {
                Id: serviceId,
                LogicalName: "service",
                Name: "Support"
            };
    }

    var jsonCustomActivity = JSON.stringify(customactivity);

    var createRequest = new XMLHttpRequest();
    createRequest.open("POST", oDataPath + "/" + oDataSetName, false);
    createRequest.setRequestHeader("Accept", "application/json");
    createRequest.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    createRequest.send(jsonCustomActivity);

错误描述:

状态:400 错误请求

错误

Error processing request stream. Error encountered in converting the value from request payload for property 'Id' to type 'Guid', 
which is the property's expected type. See inner exception for more detail.

有人可以帮我找到问题吗?

4

1 回答 1

2

服务 ID 只有 7 个字符而不是 8 个字符

var serviceId = " AFE9429 -ABCE-E211-877A-000C298A36A7";

于 2013-06-08T10:13:17.547 回答