There is a node reference field I cannot get to be posted correctly. It seems to be a bug related to the validation of node reference field, as there are 2 related issues (one of them in another module's queue) http://drupal.org/node/403140 and http://drupal.org/node/1309286

The JSON part to send this field data is:

"field_establishment":{"0":{"nid":{"nid":"26686"}}}

The first related issue http://drupal.org/node/403140 Error on autocomplete node reference field: found no valid post with that title. is for the module Node import, and it has working patch for it at comment #22

Comments

marcingy’s picture

Status: Active » Closed (works as designed)

This is not a bug the data being posted should be exactly as expected by FAPI in this case it is obviously not and hence it is failing validation.

mac_weber’s picture

I posted a tutorial of how I solved it:
http://drupal.org/node/1354202 - Services 3 - POST node.create with custom fields

sarav.din33’s picture

hi Mac_Weber,

I saw you post in http://drupal.org/node/1354202 and i follow it and posted as below,

{
 "field_review_reference":[
  {
     "nid":
        {
           "nid":"[nid:26686]"
         }
  }
 ]
}

But i received output as

{"nid": null, "uri": "http://localhost/end_point/node/" }

I track some levels, in drupal_process_form() my reference field(field_review_reference) value won't get set.

Can you guide what is the problem in my case?

Thanks & Regards
Sarav.

mac_weber’s picture

@Sarav,

maybe you are missing the part 3 of my tutorial, another cause may be not having that nid value in your database.

sarav.din33’s picture

@Mac_Weber,

I already saw part 3 of your tutorial. As per the tutorial only i gave my input as,

{
"field_review_reference":[
  {
     "nid":
        {
           "nid":"[nid:2349]"
         }
  }
]
}

And also i gave the node id as "2349". This node id available in my site.

Can you please guide me, if the following scenario will affect my node creation. I wrote the following code in my hook_form_alter()

$form['field_review_reference'] - Node Reference field ID Name.

      if($form['#node']->type == '<node type>' && arg(2) == 'edit') {
        $form['field_review_reference'][0]['#default_value']['nid'] = $form['#node']->field_review_reference[0]['nid'];
      } else {
        $form['field_review_reference'][0]['#default_value']['nid'] = arg(1);
      }

From above code i assigned the Default node reference Node ID.

I thought this scenario won't affect my node creation.

The same case in User Reference Field also. I assign some UID for that field, User won't set in Created Node.

Thanks & Regards
Sarav.