locked
Dynamics 365 : Set a Value in an editable grid in a form RRS feed

  • Question

  • Hello,

    I've got an editable subgrid in a form.

    I want to update a field in the subgrid when a value (new_montant_operation) is modified in the form.

    I manage to read the subgrid rows, and make the calculation for each rows of the subgrid, but the setValue method doesn't update the field in the subgrid.

    Here is the code :

    function MaJLignes_Investissements(){
    var montant_operation_calc = Xrm.Page.getAttribute("new_montant_operation").getValue();
    var type_op;
    var montant;
    var pourcent;
     try{
      var rows = Xrm.Page.getControl("Investissements").getGrid().getRows();
      rows.forEach(function (row, i) {
       var attributes = row.getData().getEntity().getAttributes();
       attributes.forEach(function (attribute) {
        switch (attribute.getName()) {
         case "new_type_operation" :
            type_op = attribute.getValue(); 
         break;
         case "new_op_en_pourcentage" :
    	pourcent = attribute.getValue(); 
         break;
         case "new_montant_ligne" :
    	if (type_op == 100000000) { // Les lignes sont en %
    		if (Xrm.Page.getAttribute("new_saisir_montant").getValue() == true || Xrm.Page.getAttribute("new_type_operation").getValue() != 100000000){ // Montant saisi OU arbitrage
    			montant = montant_operation_calc * pourcent / 100;
    			if (montant != "NaN") {
    				attribute.setValue(montant);
    			}
    		}
    	}
         break;
        }
       });
      });
     }
     catch(e){alert(e.message);}
    }
    
    Variable montant is well calculated and != "NaN" so setValue is executed but the field in the grid is not updated.

    Thank you in advance for your help.

    Vincent

    Friday, November 24, 2017 4:08 PM

All replies

  • Alternatively, you may execute the Web API calls to update the records in Dynamics 365 directly and then force the subgrid refresh.

    blog: http://technologynotesforyou.wordpress.com


    • Edited by Khadim Ali Thursday, November 30, 2017 6:13 PM
    Thursday, November 30, 2017 6:12 PM