简体   繁体   English

CRM 2011批量编辑表单:如何为每个记录记录更新具有不同值的某些表单字段?

[英]CRM 2011 Bulk Edit form : how to update some of the form fields with different values for each record record?

Currently I am dealing with a problem while using bulk edit functionality. 目前,我在使用批量编辑功能时遇到了问题。 I am trying to achieve the below. 我正在努力实现以下目标。 I also have given the code below. 我也给出了下面的代码。

  1. On the bulk edit form , select values from the 2 option sets. 在批量修改表单上,从2个选项集中选择值。
  2. On the change event of the value2 , it calls a javascript function. 在value2的change事件上,它调用javascript函数。

In the function,I am fetching all the records selected for bulk edit ,using window.dialogArguments, into a variable. 在函数中,我正在使用window.dialogArguments将所有要进行批量编辑的记录都提取到一个变量中。 Now in the for loop, I fetch the records one by one and then for each record I do the following: a. 现在在for循环中,我一个接一个地获取记录,然后对每个记录执行以下操作: For each record, using both optionset values seleted and some more values from the current record data, it checks conditions and decides the set of final values to be set. 对于每个记录,使用已选择的选项集值和当前记录数据中的其他一些值,它检查条件并确定要设置的最终值集。 b. b。 It tries to set these final values for some (let say 5 ) of the fields available on the bulk edit form, for that particular record using OData update. 它尝试使用OData更新为该特定记录为批量编辑表单上的某些字段(比如说5)设置这些最终值。

It is executing the loop, fetching the records, assigning it to the entity object, executing OData call and updating the values selected in step 1 (ie optionset values) , which are same for all the records. 它正在执行循环,获取记录,将其分配给实体对象,执行OData调用并更新在步骤1中选择的值(即,选项集值),这些值对于所有记录都是相同的。 For those 5 fields it should set the values as per the conditions and final value set retrieved from step b. 对于这5个字段,应根据条件和从步骤b中检索到的最终值设置值。

Instead of that, it is setting 5 field values for all records equivalent to the values retrieved from the step b , for the last record. 取而代之的是,它为最后一条记录的所有记录设置5个字段值,这些值等于从步骤b中检索到的值。

What I am suspecting is, at the end just before closing the bulk edit form, it is over-writing those 5 fields values for all the records with same values ( which is by deafult functionality of the bulk edit, I understand). 我怀疑的是,最后,在关闭批量编辑表单之前,它正在覆盖具有相同值的所有记录的那5个字段值(据我所知,这是由于批量编辑的默认功能)。

How I can prevent this last overwriting of the data values and keep the values I updated using OData previously? 如何防止最后一次覆盖数据值并保持以前使用OData更新的值?

I am kind of stuck with this now. 我现在对此感到困惑。 Any help is really appreciated. 任何帮助都非常感谢。 Below is the sample code : 下面是示例代码:

    if (Xrm.Page.ui.getFormType() == 6) { 
    var records = window.dialogArguments; 
    for(i=0; i<records.length;i++){ 
     // oDataEndpointUrl Fetch
     var requestResultsOpp= fetchData(...);

     var optionset1 = Xrm.Page.getAttribute("optionset1").getValue();
     var optionset2 = Xrm.Page.getAttribute("optionset2").getValue();

     if (requestResultsOpp != null) {
      var case_value = requestResultsOpp.field;
      var entityObject = new Object();

     /* Check values from optionset and perform some condition checks */ 

     if (some condition ) {
      switch (case_value) {
      case 3 /* XYZ */:
      case 4 /* ABCD */:
      case 5 /* PQR */:
       if (optionset1 == 1 && optionset2 == 11)
              Set the 5 fields values
       if (optionset1 == 1 && optionset2 == 12 )
              Set the 5 fields values
        break;
    default:
       if (optionset1 == 2 && optionset2 == 12 )
          Set the 5 fields values
         break;
     }
    }

   entityObject.optionset1 = {Value: optionset1};
   entityObject.optionset2 = {Value: optionset2}; 
   entityObject.Field1 = {Value: field1};
   entityObject.Field2 = {Value: field2};
   entityObject.Field3 = {Value: field3};
   entityObject.Field4 = {Value: field4};
   entityObject.Field5 = {Value: field5};

   // oDataEndpointUrl update
   updateRecordSync("entityName", record[i] ,  entityObject);
  }
 }
}

The short answer is no, you can execute javascript on a bulk edit form (OData assumes javascript in CRM). 简短的答案是没有,您可以在批量编辑表单上执行javascript(OData假定CRM中使用javascript)。 The good news is that you can execute exactly that logic within a plugin, which will execute as expected for a bulk edit. 好消息是,您可以在插件中完全执行该逻辑,该逻辑将按批量编辑的预期执行。 Within plugins, you can use pre and post entity images to compare before and after values, so you have a huge amount of flexibility as to what logic you want to perform. 在插件中,您可以使用前后实体图像来比较值之前和之后,因此,您可以灵活选择要执行的逻辑。

Your question is a bit confusing as to the final desired result, but if you want to roll back the transaction (not update the values), then you can throw an InvalidPluginExecutionException for whichever records you don't want to update, or just let the execution complete to allow the update to persist. 您的问题对于最终的期望结果有些困惑,但是如果您想回滚事务(不更新值),则可以为不想更新的记录抛出InvalidPluginExecutionException,或者只是让执行完成,以允许更新持续存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM