How to auto-assign a user a particular role when that user gets autocreated in a content form? I need to auto-assign newly autocreated users from the content editing
form a particular role.

I created this new content-type : Music Track and created a new field - Artist for it. The Artist field is entity referenced to Target type - USER. I was expecting a Roles list under Entity Selection area so that I can restrict only Artist role users to be created when creating a new content and adding new artists but its not available.  

Note: 
Users are being autocreated using Entityreference Autocreate module.
Note: I use this in a project and it works (it does not use the Entityreference Autocreate module).

First alter the artist form and add a custom validate and a custom submit

function YOUR_MODULE_NAME_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  if ($form_id == 'artist_node_form') {

            //hidding the Entity Reference field (User), it will be created in the process  
            unset($form['field_user']);

            if (!isset($node-&gt;nid) || isset($node-&gt;is_new)) {
                $form['field_username'] = array(
                    '#type' =&gt; 'container',
                    '#weight' =&gt; 3,
                    'field_username' =&gt; array(
                        '#type' =&gt; 'textfield',
                        '#title' =&gt; t('Username'),
                        '#maxlength' =&gt; 60,
                        '#description' =&gt; t('Spaces are allowed; punctuation is not allowed except for periods, hyphens, apostrophes, and underscores.'),
                        '#required' =&gt; TRUE,
                        '#attributes' =&gt; array(
                            'class' =&gt; array(
                                'username',
                                ),
                            ),
                        '#default_value' =&gt; '',
                        '#access' =&gt; TRUE,
                        '#weight' =&gt; -10,
                        )
                    );

                $form['field_password'] = array( 
                    '#type' =&gt; 'container',
                    '#weight' =&gt; 4,
                    'field_password' =&gt; array(
                        '#type' =&gt; 'password_confirm',
                        '#size' =&gt; 25,
                        '#description' =&gt; t('Provide a password for the new account in both fields.'),
                        '#required' =&gt; TRUE,
                        ),
                    );

       $form['#validate'][] = 'artist_node_form_validate';
       $form['#submit'][] = 'artist_node_form_submit';
    }
  }
}


In the custom validate you need to validate the username and check if the username is available.

function artist_node_form_validate($form, &amp;$form_state) {
    $valid_user = user_validate_name($form_state['values']['field_username']);
    if(!is_null($valid_user)) {
        form_set_error('field_username', $valid_user);
    } else {
        $user = user_load_by_name($form_state['values']['field_username']);
        if($user){
            form_set_error('field_username', t('The username @username already exist.', array('@username' =&gt; $form_state['values']['field_username'])));
        } else {
            $form['field_username'];
        }
    }
}


In the custom submit you will create the user 

function artist_node_form_submit($form, &amp;$form_state) {
    $new_user = array(
        'name' =&gt; $form_state['values']['field_username'],
        'pass' =&gt; $form_state['values']['field_password'], // note: do not md5 the password
        'mail' =&gt; $form_state['values']['field_email'][LANGUAGE_NONE][0]['email'],
        'status' =&gt; 1
        );

    //The first parameter is sent blank so a new user is created.
    $new_user = user_save('', $new_user);

    //assigning the role
    $role = user_role_load_by_name("artist");
    user_multiple_role_edit(array($new_user-&gt;uid), 'add_role', $role-&gt;rid);  

    //field_user is the Entity Reference field
    $form_state['values']['field_user'][LANGUAGE_NONE][0]['target_id'] = $new_user-&gt;uid;

}