Programmatically get the results of a view Using the group module in D8, I have the below view with machine name: group_members_per_group



Machine Name of: 


(Member account) User: Full Name is: field_user_full_name
(Member account) User: Phone Number is: field_user_phone_number


The above view has the below results:



On cron run, and while Looping through all rows of the view results, I want to get for each row the field_user_phone_number value so I can use it with other code.

So I wrote:

function my_module_cron() {

// Get and loop through the View `group_members_per_group`
//$args = [$gid];
$view = \Drupal\views\Views::getView('group_members_per_group');
//$view-&gt;setArguments($args);
$view-&gt;setDisplay('default');
$view-&gt;execute();

// Get the results of the view.
$view_result = $view-&gt;result;

// Check if the view is not empty and return results.
if (!empty($view_result)) {

// If the view returns results...
foreach ($view-&gt;result as $row) {

// Get the full name value.
$name = $row-&gt;field_user_full_name;


// check the result output for testing only.
\Drupal::messenger()-&gt;addMessage(t($name));
  }
 }
}


However, on cron run, I am receiving the below error:


  Notice: Undefined property: Drupal\views\ResultRow::$field_user_full_name in my_module_cron() (line 103 of modules\custom\my_module\my_module.module).
      my_module_cron(Object)
      call_user_func('my_module_cron', Object) (Line: 316)
      Drupal\ultimate_cron\Entity\CronJob->invokeCallback() (Line: 459)
      Drupal\ultimate_cron\Entity\CronJob->run(Object) (Line: 24)
      Drupal\ultimate_cron\Controller\JobController->runCronJob(Object)
      call_user_func_array(Array, Array) (Line: 123)
      Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber{closure}() (Line: 582)
      …
      …


Line 103 in the error is: 

$name = $row-&gt;field_user_full_name;
You can not get the value of field directly from row result.
You can get it by accessing to the entity like the following:
Option1    

  foreach ($view-&gt;result as $id =&gt; $result) {
    $node = $result-&gt;_entity;
    // Get the full name value.
    $name = $node-&gt;get('field_user_full_name')-&gt;value;
    // check the result output for testing only.
    \Drupal::messenger()-&gt;addMessage(t($name));
  }


Or by loop through the fields like the following:
Option2:  

foreach ($view-&gt;result as $id =&gt; $row) {
      foreach ($view-&gt;field as $fid =&gt; $field) {
        if ($fid == 'field_user_full_name') {
          //Get the full name value.
          $name = $field-&gt;getValue($row);
          // check the result output for testing only.
          \Drupal::messenger()-&gt;addMessage(t($name));
        }
      }
    }