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!
Nick
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,
),
What is the response from the web service?
Try to debug the web service call:
- Look in the web server log (Is the call getting through)
- Enable the SugarCRM logging and set the level to debug
- Either enable PHP error output or make PHP log errors to a log file
- Use e.g. SoapUI to test SOAP call
- See Where is SugarFullTest_Version2.php? (Sugar CRM and SOAP) for a more thorough SOAP example
- Check the SugarCRM SOAP documentation
I would also try with a simpler test and verify it works properly:
$info = $soapClient->set_entry(
$session,
'Accounts',
array(
array('name' => 'name', 'value' => 'Test account'),
array('name' => 'description', 'value' => 'This is a test account'),
)
);
}
The id will be created automatically.
精彩评论