简体   繁体   中英

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. On the change event of the value2 , it calls a javascript function.

In the function,I am fetching all the records selected for bulk edit ,using window.dialogArguments, into a variable. Now in the for loop, I fetch the records one by one and then for each record I do the following: a. 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. 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.

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. For those 5 fields it should set the values as per the conditions and final value set retrieved from step 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.

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).

How I can prevent this last overwriting of the data values and keep the values I updated using OData previously?

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). 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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