CRM - 内部服务器错误:处理多个实体时

时间:2017-12-01 22:49:57

标签: dynamics-crm dynamics-crm-2011

所以我有一个自定义操作(批准按钮),可以在编辑单个实体时触发,也可以在从实体列表视图触发时触发多个实体。

逻辑基本上删除了一个实体类型,并在批准后创建了一个具有更多字段和选项的不同实体类型。

当从只有一个实体被编辑的表单触发逻辑时,逻辑工作正常。

然而,当从列表视图运行相同的逻辑并且现在我在多个实体上进行迭代时,当我尝试为新实体类型(具有更多选项的那个)创建记录时,存在内部服务器错误。这没有任何意义,我呼吁一个已经在不同情况下工作的功能。我正在创建一个新实体,而不是更新或删除现有实体,因此不应该有锁或其他并发问题。

错误是无法提供信息的,我无法在任何地方看到任何可以帮我调试的日志。有没有人遇到过这个?

修改

我已启用CRM跟踪日志记录以查找错误(在注册表中),但这无济于事。这个内部服务器“错误”似乎不足以显示在日志中。

修改2

也许有些代码?错误发生在SDK.REST.createRecord行上,但只有当它在click处理程序的循环内运行时,当它从单个实体表单运行时,它才会创建一个没有问题的记录。

PCL.EventParticipants = {
  EventFormApproveParticipantClick: function (selectedItemIds, entityTypeName) {
    debugger;
    var anEventRequest,
        requestId,
        action,
        event,
        contact,
        emailPref,
        actualEmail;

    console.log('Approval Clicked');

    // Do this if we are working on a single event request
    if (entityTypeName == null)
    {
      requestId = Xrm.Page.data.entity.getId();
      action = Xrm.Page.data.entity.attributes.get("pcl_action").getValue();
      var participant =  PCL.EventParticipants.MakeParticipant(
        Xrm.Page.data.entity.attributes.get("pcl_contact").getValue()[0].id,
        Xrm.Page.data.entity.attributes.get("pcl_event").getValue()[0].id,
        Xrm.Page.data.entity.attributes.get("pcl_name").getValue(),
        Xrm.Page.data.entity.attributes.get("pcl_emailpreference").getValue(),
        Xrm.Page.data.entity.attributes.get("pcl_selectedemail").getValue()
      );
      if (PCL.EventParticipants.Act(requestId, action, participant)) {
        alert('Approval complete.');
      }
      return;
    }

    var opSuccess = true;
    // When multiple requests are selected do...
    for (var x = 0; x < selectedItemIds.length; x++) {
      requestId = selectedItemIds[x];

      SDK.REST.retrieveRecord(
        requestId,
        "pcl_eventrequest",
        "pcl_eventrequestId,pcl_Action,pcl_Contact,pcl_Event,pcl_name,pcl_EmailPreference,pcl_SelectedEmail", null,
        function (anEventRequest) {
          requestId = anEventRequest.pcl_eventrequestId;
          action = anEventRequest.pcl_Action.Value;
          var participant = PCL.EventParticipants.MakeParticipant(
            anEventRequest.pcl_Contact.Id,
            anEventRequest.pcl_Event.Id,
            anEventRequest.pcl_name,
            anEventRequest.pcl_EmailPreference,
            anEventRequest.pcl_SelectedEmail
          );

          if (!PCL.EventParticipants.Act(requestId, action, participant)) {
            opSuccess = false;
          }
        },
        function(error) {
          alert('Could not retrieve selected event request: ' + requestId + '  Check that it has not been removed from the system.  -->  ' + error.message);
        }, false
      );
    }

    if (opSuccess) {
      alert('Approvals completed.');
    } else {
      alert('One or more Approvals failed.');
    }
  },
  Act: function (requestId, actionValue, participant) {
    var opSuccess = false;

    if (actionValue == '798330000') {
      // Add action
      opSuccess = PCL.EventParticipants.CreateEventParticipant(participant);
    }

    if (actionValue == '798330001') {
      // Remove action
      opSuccess = PCL.EventParticipants.RemoveEventParticipant(participant);
    }

    if (opSuccess == false) {
      return opSuccess;
    }

    opSuccess = PCL.EventParticipants.RemoveParticipantRequest(requestId);

    return opSuccess
  },
  CreateEventParticipant: function (eventParticipant) {
      var existingParticipant = PCL.EventParticipants.RetrieveEventParticipantLike(eventParticipant.pcl_Event.Id, eventParticipant.pcl_Contact.Id);

      if (existingParticipant != null) {
          alert('Cannot approve this request.  This contact is already participating in the selected event.');
          return false;
      }

      var opSuccess = false;
      SDK.REST.createRecord(
        eventParticipant,
        "pcl_eventparticipant",
        function (result) {
          opSuccess = true;
        },
        function(error) {
          alert('Could not create event request with contactId: ' + eventParticipant.pcl_Contact.Id + ' and eventId: ' + eventParticipant.pcl_Event.Id + '.  -->  ' + error.message);
        }, false
      );
      return opSuccess;
  }, .....
}

编辑3

我已经修改了SDK.REST以获得第5个参数,该参数用于切换操作是同步还是异步。在任何操作结束时传递false都会使操作同步。

0 个答案:

没有答案