1
0
-1

Hi All,

I have used below code to copy data from grid table to parent table (into speciefic field), it returns all grid data in an array.

How can I modify below code to have in parent table field Parent1 only speciefic record from Grid table field2, eg. only 3rd record so when i = 3 which means result 145.

Thanks for help in this one.

<script type="text/javascript">
    $(document).change(function(){
//this is field in parent table
        var fieldId1 = "parent1";
        
//get value from parent form
        var values1 = FormUtil.getGridCellValues("grid.field2");
for (var i = 0; i < values1.length; i++) {
    console.log(values1[i]); //i equals to row number start from 0
}
 
        //store the value to a parent table field
        $('[name='+fieldId1+']:enabled').val(values1);
    });
</script>
    CommentAdd your comment...

    6 answers

    1.  
      2
      1
      0

      eg. only 3rd record so when i = 3 which means result 145.

      $('[name='+fieldId1+']:enabled').val(values1[2]); //third record means index 2

       

       

        CommentAdd your comment...
      1.  
        1
        0
        -1

        Hi Jedi,

        it works for me, did you used correct reference to Grid table in javascript?

          CommentAdd your comment...
        1.  
          1
          0
          -1

          hi, i tried using this but my error log shows "FormUtil" was not defined. what will i do?

            CommentAdd your comment...
          1.  
            1
            0
            -1

            Hi, 

            Just a suggestion, you may need to change your code to use FormUtil.getField to retrieve field to set value. FormUtil.getField will auto handle the case that this form is used as a subform.

             

            <script type="text/javascript">
                $(document).change(function(){
                    //define fields from parent form
                    var fieldId1 = "parent_all";
                    var fieldId2 = "parent1";
                    var fieldId3 = "parent2";
                    var fieldId4 = "parent3";
                    var fieldId5 = "parent4";
                    var fieldId6 = "parent5";
                    var fieldId7 = "parent6";
                    var fieldId8 = "parent7";
                    var fieldId9 = "parent8";
                    var fieldId10 = "parent_yes";
                    
                    //get values from grid data       
                    var values1 = FormUtil.getGridCellValues("grid.id");
                    
                    //get values from grid data where value = 'Yes'
                    var diff = "NO"; 
                    var values2 = FormUtil.getGridCellValues("grid.field4");
                    for (var i = 0; i < values2.length; i++ ) {
                        if (values2[i] === 'Yes') {
                          diff = values1[i];
                          break;
                        }
                    }
                    /* 
                      NOTE: I would suggest you to use FormUtil.getField to retrieve field and set value.
                      This will auto handle the case that this form is used as a subform.
                    */
             
                    //store the value to a parent field
                    FormUtil.getField(fieldId1).val(values1);
                    FormUtil.getField(fieldId2).val(values1[0]);
                    FormUtil.getField(fieldId3).val(values1[1]);
                    FormUtil.getField(fieldId4).val(values1[2]);
                    FormUtil.getField(fieldId5).val(values1[3]);
                    FormUtil.getField(fieldId6).val(values1[4]);
                    FormUtil.getField(fieldId7).val(values1[5]);
                    FormUtil.getField(fieldId8).val(values1[6]);
                    FormUtil.getField(fieldId9).val(values1[7]);
                     
                    //store the value to a parent field where value = 'YES'
                    FormUtil.getField(fieldId10).val(diff);
                     
                });
            </script>

             

            Best regards.

              CommentAdd your comment...
            1.  
              1
              0
              -1

              Hi,

              I have managed to make it, however in field parent_yes I'm getting always value for highest number with "yes".

              It's fine for me (as the will be only one yes) but maybe anybody has better idea to make it?

               

               

              <script type="text/javascript">
                  $(document).change(function(){
              //define fields from parent form
                      var fieldId1 = "parent_all";
                      var fieldId2 = "parent1";
                      var fieldId3 = "parent2";
                      var fieldId4 = "parent3";
                      var fieldId5 = "parent4";
                      var fieldId6 = "parent5";
                      var fieldId7 = "parent6";
                      var fieldId8 = "parent7";
                      var fieldId9 = "parent8";
                      var fieldId10 = "parent_yes";
              //get values from grid data        
                      var values1 = FormUtil.getGridCellValues("grid.id");
              for (var i = 0; i < values1.length; i++) {
                  console.log(values1[i]); //i equals to row number start from 0
              }
              //get values from grid data where value = 'Yes'
                      var values2 = FormUtil.getGridCellValues("grid.field4");
              for (var i = 0; i < values2.length; i++ ) {
                   diff = "NO";		
                         if (values2[0] == 'Yes') {		
                         diff = values1[0];		
                        }	
                         if (values2[1] == 'Yes') {		
                         diff = values1[1];		
                        }	   
                         if (values2[2] == 'Yes') {		
                         diff = values1[2];		
                        }	  
                         if (values2[3] == 'Yes') {		
                         diff = values1[3];		
                        }	  
                        if (values2[4] == 'Yes') {		
                         diff = values1[4];		
                        }	  
                         if (values2[5] == 'Yes') {		
                         diff = values1[5];		
                        }	  
                         if (values2[6] == 'Yes') {		
                         diff = values1[6];		
                        }	  
                         if (values2[7] == 'Yes') {		
                         diff = values1[7];		
                        }	  
                         if (values2[8] == 'Yes') {		
                         diff = values1[8];		
                        }	  
                         if (values2[9] == 'Yes') {		
                         diff = values1[9];		
                        }	  
                         if (values2[10] == 'Yes') {		
                         diff = values1[10];		
                        }	  
              }
              
               
                      //store the value to a parent field
                      $('[name='+fieldId1+']:enabled').val(values1);
                      $('[name='+fieldId2+']:enabled').val(values1[0]);
                      $('[name='+fieldId3+']:enabled').val(values1[1]);
                      $('[name='+fieldId4+']:enabled').val(values1[2]);
                      $('[name='+fieldId5+']:enabled').val(values1[3]);
                      $('[name='+fieldId6+']:enabled').val(values1[4]);
                      $('[name='+fieldId7+']:enabled').val(values1[5]);
                      $('[name='+fieldId8+']:enabled').val(values1[6]);
                      $('[name='+fieldId9+']:enabled').val(values1[7]);
                      
                      //store the value to a parent field where value = 'YES'
                      $('[name='+fieldId10+']:enabled').val(diff);
                      
                  });
              </script>
                CommentAdd your comment...
              1.  
                1
                0
                -1

                Hi Walter,

                thanks! works perfectly.

                Now I have the following question, I would like to see in the parent form in field parent_yes  field ID from child form where  field4="Yes".

                I believe I need to update somehow var values2 part with if condition eg. if grid,field4="Yes".

                So in below case I would get result: ID-000045 

                Any luck with this one please?

                 

                 

                <script type="text/javascript">
                    $(document).change(function(){
                //define fields from parent form
                        var fieldId1 = "parent_all";
                        var fieldId2 = "parent1";
                        var fieldId3 = "parent2";
                        var fieldId4 = "parent3";
                        var fieldId5 = "parent4";
                        var fieldId6 = "parent5";
                        var fieldId7 = "parent6";
                        var fieldId8 = "parent7";
                        var fieldId9 = "parent8";
                        var fieldId10 = "parent_yes";
                //get values from grid data        
                        var values1 = FormUtil.getGridCellValues("grid.id");
                for (var i = 0; i < values1.length; i++) {
                    console.log(values1[i]); //i equals to row number start from 0
                }
                //get values from grid data where value = 'Yes'
                        var values2 = FormUtil.getGridCellValues("grid.id");
                for (var i = 0; i < values2.length; i++ ) {
                    console.log(values2[i]); //i equals to row number start from 0
                }
                 
                        //store the value to a parent field
                        $('[name='+fieldId1+']:enabled').val(values1);
                        $('[name='+fieldId2+']:enabled').val(values1[0]);
                        $('[name='+fieldId3+']:enabled').val(values1[1]);
                        $('[name='+fieldId4+']:enabled').val(values1[2]);
                        $('[name='+fieldId5+']:enabled').val(values1[3]);
                        $('[name='+fieldId6+']:enabled').val(values1[4]);
                        $('[name='+fieldId7+']:enabled').val(values1[5]);
                        $('[name='+fieldId8+']:enabled').val(values1[6]);
                        $('[name='+fieldId9+']:enabled').val(values1[7]);
                        
                        //store the value to a parent field where value = 'YES'
                        $('[name='+fieldId10+']:enabled').val(values2);
                        
                    });
                </script>
                  CommentAdd your comment...