How to create (& pre-populate) multiple “field collection” fields on an ajax call This is an extension of this question - "How to pre-populate multiple &quot;field collection&quot; fields in node form"

I'm trying to do the same thing, but I'm trying to get it to work on an ajax call rather than on the form load. 

The form loads, the user selects an option on a dropdown and then the form automatically populates several field collections with ajax.

The Problem

The existing solution on the question above involves altering the form when it's first built, by changing:  

 $form_state['field']['--machine-name-of-field--'][LANGUAGE_NONE]['items_count']


And then rebuilding the form using the new form state values.

The problem with an ajax call is that, it seems to ignore any changes made to $form_state in the callback. i.e. 

function ajax_get_parent_field_collection ($form, &amp;$form_state) {
  $form_state['field']['field_collection_entity']['und']['items_count'] = '3';
  return $form['field_collection_entity'];
}


The changes made in $form_state above are ignored, so when the form is rebuilt nothing happens and if you then dump $form_state none of the changes made are saved.

I could manually create the field collection entities and insert them, but I was hoping there's a cleverer answer. Has anyone tackled this before?

EDIT:

The ajax is currently called on a select field, so the ajax triggers when the select dropdown is used.

$form['field_company_for_center']['und']['#ajax'] = array (
  'callback' =&gt; 'ajax_get_parent_field_collection',
  'wrapper' =&gt; 'ajax-wrapper',
  'effect' =&gt; 'fade',
);
The form needs to be build again after items_count is changed.

function MYMODULE_form_alter (&amp;$form, &amp;$form_state, $form_id) {
  if($form_id == 'MYFORM'){
    $form['#attributes']['id'] = 'MYMODULE-form-ajax-wrapper';

    // Handle triggered ajax element.
    if(!empty($form_state['triggering_element']['#array_parents'][0])) {
      if ($form_state['triggering_element']['#array_parents'][0] == 'field_node_reference') {
        $form_state['field']['field_collection_entity'][LANGUAGE_NONE]['items_count'] = '3';
      }
    }

    // Add ajax callback.
    $form['field_node_reference'][LANGUAGE_NONE]['#ajax'] = array (
      'callback' =&gt; 'MYMODULE_ajax_rebuild_form',
      'wrapper' =&gt; 'MYMODULE-form-ajax-wrapper',
    );
  }
}

/**
 * Ajax callback, rebuilds and returns the entire form.
 */
function MYMODULE_ajax_rebuild_form ($form, &amp;$form_state) {
  return drupal_rebuild_form($form_state['build_info']['form_id'], $form_state, $form);
}