HOWTO: Specify the ID for a newly created record via Web Services

sugarcrmdevelopers —  January 9, 2012 — 2 Comments

I saw this message come up on Stack Overflow the other day:

How to insert a row into the Accounts table via the Sugar API

This is code I have tried:

$result = $sugar['soapclient']->call(
    'set_entry',
    array(
        'session'=>$sugar['session'],
        'module_name'=>'Accounts',
        array(
            array("name" => 'id', "value" => $sugar_data['id']),
            array("name" => 'name', "value" => $sugar_data['name']),
            array("name" => 'description', "value" => $sugar_data['description']),
            array("name" => 'team_id', "value" => $sugar_data['team_id']),
            array("name" => 'team_set_id', "value" => $sugar_data['team_set_id']),
            array("name" => 'phone_fax', "value" => $sugar_data['phone_fax']),
            array("name" => 'billing_address_street', "value" => $sugar_data['address_street']),
            array("name" => 'billing_address_city', "value" => $sugar_data['address_city']),
            array("name" => 'billing_address_state', "value" => $sugar_data['address_state']),
            array("name" => 'billing_address_postalcode', "value" => $sugar_data['address_postalcode']),
            array("name" => 'billing_address_country', "value" => $sugar_data['address_country']),
            array("name" => 'shipping_address_street', "value" => $sugar_data['address_street']),
            array("name" => 'shipping_address_city', "value" => $sugar_data['address_city']),
            array("name" => 'shipping_address_state', "value" => $sugar_data['address_state']),
            array("name" => 'shipping_address_postalcode', "value" => $sugar_data['address_postalcode']),
            array("name" => 'shipping_address_country', "value" => $sugar_data['address_country']),
            array("name" => 'phone_office', "value" => $sugar_data['phone_work'])
        )
    )
);

However, the row does not insert. I searched based on the ID and the account_name, and both returned 0 results.

Thanks! I really appreciate the help, as this is due for completion by the end of the day today!

Luckily our very our Sugar Community Superstar Cédric Mourizard was right on top of it, and posted that passing in the ‘new_with_id’ parameter set to true works over the Web Services API just like it does inside the application. So to fix the problem, here’s the solution he posted:

I think the problem is that you used “id” field in your data. In this case, SugarCRM try to update account record with this specific ID. If you want to create an account with you own id you should to add also this element in your array :

array(
    'name' => 'new_with_id',
    'value' => 1,
),

 

2 responses to HOWTO: Specify the ID for a newly created record via Web Services

  1. 

    I know this post is old, but I’m running into a similar situation. I’m wondering if this is possible to do by passing ‘new_with_id’ in along with a query string to the LeadCapture page. We are currently working on some changes to our inbound lead flow and we need to specify a lead_id prior to insertion. ANY help would be greatly appreciated!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s