AnsweredAssumed Answered

set_relationship() is not working in REST

Question asked by Sachin Sachin on Jun 2, 2014
Latest reply on Jun 3, 2014 by paperless
Custom module Order & Products have one to many relationship,
Trying to insert record using REST API,
Record is inserted but relationship is not set , pls help
my code is:-



//create order -------------------------------------     $set_entry_parameters = array(
         //session id
         "session" => $session_id,

         //The name of the module from which to retrieve records.
         "module_name" => "man_odrer_list",

         //Record attributes
         "name_value_list" => array(
              //to update a record, you will nee to pass in a record id as commented below
         array("name" => "id", "value" => "44a17e4e-af64-389c-11b8-538c68dc01d4"),
              array("name" => "description", "value" =>  $variable5),
     array("name" => "assigned_user_id", "value" => $variable7),
     array("name" => "created_by", "value" => $variable4),
    
         ),
    );


  $set_entry_result = call("set_entry", $set_entry_parameters, $url);
$order_id = $set_entry_result->id;
echo $order_id;

//create products
 $set_entry_parameters = array(
         //session id
         "session" => $session_id,

         //The name of the module from which to retrieve records.
         "module_name" => "man_product_list",

         //Record attributes
         "name_value_list" => array(
              //to update a record, you will nee to pass in a record id as commented below
          array("name" => "id", "value" => "b9baf79d-6feb-59bf-b355-538c68d956d3"),
              array("name" => "name", "value" => $product_name) ,   
   // array("name" => "man_odrer_list_man_product_list_1_name", "value" => '1400087')
         ),
    );


  $set_entry_result = call("set_entry", $set_entry_parameters, $url);
$product_id = $set_entry_result->id;
echo $product_id;



//set relationship ----------------------------------------

   $set_relationship_parameters = array(
    //session id
    'session' => $session_id,

    //The name of the module.
    'module_name' => 'man_product_list',

    //The ID of the specified module bean.
    'module_id' => '$order_id',

    //The relationship name of the linked field from which to relate records.
    'link_field_name' => 'man_odrer_list_man_product_list_1',

    //The list of record ids to relate
    'related_ids' => array(
        '$product_id',
    ),

   
    //Whether or not to delete the relationship. 0:create, 1:delete
    'delete'=> 0,
); 

Outcomes