Fetch the Account ID based on Primary Emailaddress in Sugar CRM - soap

We have a website and when a record is inserted / updated we runs a script to update the sugar CRM Accounts module.
The Accounts module have a field website_id_c . When an insert occurs to DB we set the last insert ID to website_id_c of Sugar CRM and the remaining values to get inserted.
Insert script is something like below .
$name_value_field=array(
array('name' => 'name','value' => $name),
array('name' => 'primary_contactperson_c','value' => $ownername),
array('name' => 'billing_address_street','value' => $address),
array('name' => 'billing_address_postalcode','value' => $postalcode),
array('name' => 'email1','value' => $email),
array('name' => 'website_id_c','value' => $id_retrieved),
);
if(!empty($sessn_id))
{
$result=$soap->set_entry("Accounts",$name_value_field);
}
This uses the SOAP nusoap client to communicate with Sugar CRM cloud. Insertion works fine and update also.
$response = $soap->get_entry_list('Accounts',
array('id'),
"website_id_c='$websiteID'");
$account_id = $response['entry_list'][0]['id'];
But currently I want to retrieve the account_id to update the record on the basis on Email. I changed the fields with email . But I feel its stored in some other place and the primary address key is stored in the Accounts module. So first we want to fetch that id from the Email module, and then query the Accounts module on the basis of this Email address id to get the Account Values.
$response = $soap->get_entry_list('Accounts',
array('id'),
"email1='email#example.com'");
Which is the module that stores the Email address ? I have not worked on Sugar before. So feel free to ask me if you didn't get me exactly.
Thanks

The email field and its relation to accounts is stored in two other tables, so you need to retrieve the accounts with a sub select.
$response = $soap->get_entry_list(
$module = 'Accounts',
$fields = array('id'),
$query = "accounts.id IN (
SELECT eabr.bean_id
FROM email_addr_bean_rel eabr
JOIN email_addresses ea ON (ea.id = eabr.email_address_id)
WHERE
eabr.bean_module = 'Accounts'
AND eabr.deleted = 0
AND ea.email_address = 'email#example.com'
)",
$orderBy = "accounts.name",
$offset = 0,
$max = 10
);
My soap clients get_entry_list method is as
get_entry_list($module,
$fields = array(),
$query='',
$order_by='',
$offset=0,
$limit = 1000)
Make the necessary changes accordingly .

Related

Retrieve the user id who posts a single entry of Gravity Form

Suppose that I know the entry ID ($lead_id), how can I retrieve the user who creates that entry.
I try to
$lead = RGFormsModel::get_lead( $lead_id );
$form = GFFormsModel::get_form_meta( $lead['form_id'] );
$values= array();
foreach( $form['fields'] as $field ) {
$values[$field['id']] = array(
'id' => $field['id'],
'label' => $field['label'],
'value' => $lead[ $field['id'] ],
);
}
But the user data is not there. I check sql database, and the user data is in wp_rg_lead table, not in wp_rg_lead_detail table.
Can anybody please help?
The information in the *_rg_lead table is accessible in the array that's returned by the get_lead function. So
user_id = $lead['created_by']
Also note that it's better to use the Gravity Forms API for retrieving the entry, specifically the get_entry function:
GFAPI::get_entry( $entry_id )
which will return an Entry object.

Can't Relate Contact and Opportunity in SuiteCRM / SugarCRM CE

I'm working on a script to import data into SuiteCRM / SugarCRM CE. I need to create a Contact and an Opportunity. I then need to relate the two.
I have a many to many relationship between Contacts and Opportunities. Each contact should be able to create multiple opportunities. Each opportunity should be able to be assigned to multiple contacts.
When I run the code it says "1 Relationship(s) created", but when I check Suite there's nothing listed under the contact or opportunity subpanels.
FYI, I renamed the Opportunities module "Gigs" and am using this API Wrapper: github.com/asakusuma/SugarCRM-REST-API-Wrapper-Class
Here's the code:
<?php
// Load Composer Dependencies for Sugar API Wrapper
require_once('vendor/autoload.php');
// Create Sugar Object
$sugar = new \Asakusuma\SugarWrapper\Rest;
// Set Sugar Connection Items
$sugar->setUrl('https://example.com/suitecrm/service/v2/rest.php');
$sugar->setUsername('User');
$sugar->setPassword('Pass');
// Connect to Sugar
$sugar->connect();
// Did something go wrong with the connection? Report it.
$error = $sugar->get_error();
if($error !== FALSE) {
return $error['name'];
}
// Ok... We're going to try and create a test entry in Sugar/Suite
// Create a Contact
$modules = 'Contacts';
// Set Values
$values = array(
'contact_type_c' => 'Prospect',
'lead_source' => 'Website',
'first_name' => 'Test',
'last_name' => 'Contact',
'phone_mobile' => '(123) 456-7890',
'email1' => 'test#test.com'
);
// Put it in Suite
$result = $sugar->set($modules, $values);
$contactID = $result['id'];
// Ok, now let's create a Opportunity
$modules = "Opportunities";
$values = array(
'name' => 'My Test Gig',
'sales_stage' => 'New Inquiry',
'amount' => '400'
);
$result = $sugar->set($modules, $values);
$gigID = $result['id'];
// Lastly, let's relate the two - HERE'S WHERE I HAVE PROBLEMS!
// Set Relationship
$moduleName = 'Contacts';
$moduleID = $contactID;
$linkFieldName = 'opportunities';
$relatedIDs = array($gigID);
$nameValueList = array(); // Passing empty array because we don't have any fields that need it
$delete = 0;
$result = $sugar->set_relationship($moduleName, $moduleID, $linkFieldName, $relatedIDs, $nameValueList, $delete);
echo $result['created'] . " relationship(s) made";
?>
The Contact and Opportunity are created just fine. It's the relationship that's not happening.
Ugh... Ok, I get it.
I looked at the API documentation and was passing $relatedIDs back as an array. What I didn't realize is that the API was doing this as well. So what got passed into Suite was a multidimensional array instead of a single array.

get_entry_list() method with query parameter on sugar crm 7 does not work

My code is as below..
Please note that I am trying to retrive all the accounts whose where the Accounts.name='bhagya'.
The same query workes for me in SugarCRM Version 6.5 (Community edition) but in case of SugarCRM 7 it is not working when I mention query parameter. If I mention 'query'=>'' then I get all the records from the sugarcrm 7 server. It fails when I specify any filter for query parameter. I am using RestAPI - 4.1
$get_entry_list_parameters = array(
//session id
'session' => $session_id,
//The name of the module from which to retrieve records
'module_name' => 'Accounts',
//The SQL WHERE clause without the word "where".
//'query' => "Accounts.billing_address_postalcode='60329'",
// 'query' => "Accounts.name='Ingrid Rofalsky'",
'query'=>'',
//The SQL ORDER BY clause without the phrase "order by".
'order_by' => "",
//The record offset from which to start.
'offset' => 0,
//A list of fields to include in the results.
'select_fields' => array(
'id',
'name',
),
//A list of link names and the fields to be returned for each link name.
'link_name_to_fields_array' => array(),
//The maximum number of results to return.
'max_results' => 10,
//If deleted records should be included in results.
'deleted' => 0,
//If only records marked as favorites should be returned.
'favorites' => false,
);
print_r($get_entry_list_parameters);
$get_entry_list_result = call('get_entry_list', $get_entry_list_parameters, $url);
echo '<pre>';
print_r($get_entry_list_result);
echo '</pre>';
Can some one help me on this..
Thank you.
Regards
- Bhagya
The Rest API has changed a lot in Sugar7.
The URL for the invokation should look like
http://servname.com/pro720/rest/v10/Accounts?filter[0][name][$starts]=B&filter[0][email_addresses.email_address]=burgers#example.com&fields=name,account_type,description,email
Where you are filtering the accounts with a name that starts with B, the mail address is burgers#example.com and where you retrieve only the fields name,account_type,description and email
Changing the module name to lowercase in query option solved this problem.
I got the answer for my query from below link.
https://community.sugarcrm.com/sugarcrm/topics/get_entry_list_method_with_query_parameter_on_sugar_crm_7_does_not_work?topic-reply-list%5Bsettings%5D%5Bfilter_by%5D=all&topic-reply-list%5Bsettings%5D%5Bpage%5D=1#reply_14588280
Thanks again
Regards
- Bhagya

Can someone provide a php sample using nusoap/sugarcrm api to create an acct/lead in sugarcrn?

Can someone provide a sample code chunk of php using the sugarcrm API/nusoap for adding creating an acct. and then linking a lead to the acct?
I've got a sample function that adds a lead, and I can see how to create an acct, but I can't see how to tie a lead to the acct, to simulate the subpanel process in the sugarcrm acct/subpanel process.
thanks
// Create a new Lead, return the SOAP result
function createLead($data)
{
// Parse the data and store it into a name/value list
// which will then pe passed on to Sugar via SOAP
$name_value_list = array();
foreach($data as $key => $value)
array_push($name_value_list, array('name' => $key, 'value' => $value));
// Fire the set_entry call to the Leads module
$result = $this->soap->call('set_entry', array(
'session' => $this->session,
'module_name' => 'Leads',
'name_value_list' => $name_value_list
));
return $result;
}
$result = $sugar->createLead(array(
'lead_source' => 'Web Site',
'lead_source_description' => 'Inquiry form on the website',
'lead_status' => 'New',
'first_name' => $_POST['first_name'],
'last_name' => $_POST['last_name'],
'email1' => $_POST['email'],
'description' => $_POST['message']
));
You need to find the ID for the account and assign that ID to whatever the account_id field name is in the Lead Module. I have run into a couple things like this before and I have found it easier to go straight to the Sugar database. So, write a statement that will return the account is, for example: SELECT id WHERE something_in_the_account_table = something else;
Then you can assign that id in your $result array. I hope it helps. I didn't have any code or documentation in front of me or I would have helped more.

Get list of all documents related to an account

I'm working on an app to download all notes and documents related to an account in Sugar CRM. I'm building it as a C# console application, using the web service API as a web reference in my solution.
I think I have figured out the notes part but I can't figure out the documents part. Can anyone show me how to get a list of all documents per account using the web service API calls?
I am assuming that I should use get_relationships() to get documents, but how do I get the accounts module id? I don't have access to the database.
(My client is using sugar crm version 6.7.1 corporate)
Okay, that you should use the API get_relationships. See the example to follow.
<?php
$get_relationships_parameters = array(
'session'=>$session_id,
//The name of the module from which to retrieve records.
'module_name' => 'Accounts',
//The ID of the specified module bean.
'module_id' => '13111fcd-1884-2a71-0b37-50b7d0f188f6',
//The relationship name of the linked field from which to return records.
'link_field_name' => 'documents',
//The portion of the WHERE clause from the SQL statement used to find the related items.
'related_module_query' => '',
//The related fields to be returned.
'related_fields' => array(
'id',
'name',
),
//For every related bean returned, specify link field names to field information.
'related_module_link_name_to_fields_array' => array(
),
//To exclude deleted records
'deleted'=> '0',
//order by
'order_by' => '',
//offset
'offset' => 0,
//limit
'limit' => 5,
);
$get_relationships_result = call("get_relationships", $get_relationships_parameters, $url);
?>
and you see result:
stdClass Object
(
[entry_list] => Array
(
[0] => stdClass Object
(
[id] => 8b4c0450-1922-498f-4601-52272fa6e494
[module_name] => Documents
[name_value_list] => stdClass Object
(
[id] => stdClass Object
(
[name] => id
[value] => 8b4c0450-1922-498f-4601-52272fa6e494
)
[name] => stdClass Object
(
[name] => name
[value] => WebProxyService_A.png
)
)
)
)
[relationship_list] => Array
(
)
)
at url https://gist.github.com/amusarra/6436845 you will find the complete example. To get the account Id should use the API or get_entry get_entries.
I hope I have been of help.
Antonio