SOAP 4 set_relationship not working - php

After battling for getting more than 20 entries with get_entry_list, i'm now trying to use the SOAP API on SugarCRM 6.5 to set a relationship between two elements, created from a form on the user-land website.
The set_relationship method is described as following in the devs blog :
$response = set_relationship(session, module_name, module_id, link_field_name, related_ids, name_value_list, delete);
So here is the code which handles the request, assuming that another part of the code handles the security.
$values = array( 'id_frame' => $_POST['id_frame'],
'id_battery' => $_POST['id_battery'],
'reseller' => $_POST['reseller'],
'date_purchase' => $_POST['date_purchase'],
'products_versionning' => $_POST['product_purchased'],
'first_name' => $_POST['first_name'],
'last_name' => $_POST['name'],
'phone_home' => $_POST['phone'],
'email' => $_POST['email'],
'primary_address_street' => $_POST['address'],
'primary_address_street_2' => $_POST['address2'],
'primary_address_street_city' => $_POST['city'],
'primary_address_street_postalcode' => $_POST['zip'],
);
try{
$prod_register = $soapClient->set_entry(
$sessid,
'myco_product_register',
array( array('name' => 'id_frame', 'value' => $values['id_frame']),
array('name' => 'id_battery', 'value' => $values['id_battery']),
array('name' => 'date_purchase', 'value' => $values['date_purchase']),
array('name' => 'first_name', 'value' => $values['first_name']),
array('name' => 'last_name', 'value' => $values['last_name']),
array('name' => 'phone_home', 'value' => $values['phone_home']),
array('name' => 'email', 'value' => $values['email']),
array('name' => 'primary_address_street', 'value' => $values['primary_address_street']),
array('name' => 'primary_address_street_city', 'value' => $values['primary_address_street_city']),
array('name' => 'primary_address_street_postalcode','value' => $values['primary_address_street_postalcode']),
array('name' => 'description','value' => "Modèle : " . $values['products_versionning'] . "\nAcheté le " . $values['date_purchase'] . " à " . $values['reseller']),
)
);
$client = $soapClient->set_entry(
$sessid,
'Accounts',
array( array('name' => 'name', 'value' => $values['first_name'] . ' ' . $values['last_name']),
array('name' => 'billing_address_street', 'value' => $values['primary_address_street']),
array('name' => 'billing_address_city', 'value' => $values['primary_address_street_city']),
array('name' => 'billing_address_postalcode', 'value' => $values['primary_address_street_postalcode']),
)
);
$entry_id = $prod_register->id;
$relationship_parameters = array(
"module1" => "myco_product_register",
"module1_id" => array($entry_id),
"module2" => "myco_products_versionning",
"module2_id" => array($values['products_versionning'])
);
//Now i'm setting the relationships
$response = $soapClient->set_relationship($sessid, "myco_product_register", $entry_id,
'myco_products_versionning_id_c', $values['products_versionning'], array(), 0);
$response = $soapClient->set_relationship($sessid, "myco_product_register", $entry_id,
'myco_resellers_id_c', $values['reseller'], array(), 0);
Both set_entry requests work and return a working id, but no one of the relationships work ($responses contains a failed equal to 1). So that's not a connection problem or such.
Talking about the relationships, one guy from the devblog said that
there has to be a relationship between the two modules
there has to be at least one related field in the module which handle the relation, whose name you can find in the module's vardefs.php
and i have
A One-to-one relationship between the product_register module and both products_versionning and resellers
A related field in product_register for each related module.
What may i be missing ?

try checking the log file of SugarCRM, you should find some mistakes. I used this API to create a relationship between Contacts and Accounts, and working properly. On the logs might find the answer to the problem.
try {
$result = $this->soapClient->set_relationship($this->sessionId,
$accountModuleName, $accountId, $relationName, $contactsId);
$this->doEvent(self::EVENT_WS_OPERATION_CALL);
if ($result->created > 0 && $result->failed === 0) {
return true;
} else {
return false;
}

Related

how to loop and array to create a TABLE in laravel with phpdocx

I am using phpdocx to generate an array with my data in a docx format.
$contact is an array of multiple object. Sometimes $contact contain 1 object, and sometimes more.
I want to make a loop, to add contact as much as I need.
My problem : For exemple, If I am doing this I will get an error like "Undefined array key 3" if my contact data only contain 3 object or less.
important : Here, if my datas contain 4 object (from 0 to 3 ) it will work but doesn't work when i have 2 objects.
$contact= array(
array(
'name' => $request->get('contact')[0]['name'],
'userName' => $request->get('contact')[0]['userName'],
'number' => $request->get('contact')[0]['number'],
'mail' => $request->get('contact')[0]['mail'],
),
array(
'name' => $request->get('contact')[1]['name'],
'userName' => $request->get('contact')[1]['userName'],
'number' => $request->get('contact')[1]['number'],
'mail' => $request->get('contact')[1]['mail'],
),
array(
'name' => $request->get('contact')[2]['name'],
'userName' => $request->get('contact')[2]['userName'],
'number' => $request->get('contact')[2]['number'],
'mail' => $request->get('contact')[2]['mail'],
),
array(
'name' => $request->get('contact')[3]['name'],
'userName' => $request->get('contact')[3]['userName'],
'number' => $request->get('contact')[3]['number'],
'mail' => $request->get('contact')[3]['mail'],
),
);
$docx->replaceTableVariable($contact, array('parseLineBreaks' => true));
what i am actually trying with no success for the moment : https://www.phpdocx.com/en/forum/default/topic/1773
I have make a loop and it is now working
$contactData = $request->get('contact');
$contactTab = array();
for ($i = 0; $i < count($contactData); $i++) {
$rowData = array(
'name' => $contactData[$i]['name'],
'userName' => $contactData[$i]['userName'],
'number' => $contactData[$i]['number'],
'mail' => $contactData[$i]['mail'],
);
$contactTab[] = $rowData;
}
$docx->replaceTableVariable($contactTab, array('parseLineBreaks' => true));

Problem while adding Journal Entry with customer in Quickbook - Message: Passed array has no key for 'Value' when contructing an ReferenceType

I go through this documentation "https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/journalentry"
And tried to add journal entry with line having customer as shown in the below code:
$journal_entry_create['TxnDate'] = date('Y-m-d');
$journal_entry_line = array(
'Amount' => $amount,
'DetailType' => 'JournalEntryLineDetail',
'JournalEntryLineDetail' => array(
'PostingType' => Credit,
'Entity' => array(
'Type' => 'Customer',
'EntityRef' => array(
'type' => 'Customer',
'value' => "2",
'name' => 'Abc'
)
),
'AccountRef' => array(
'name' => 'Account Name',
'value' => '1'
),
)
);
$journal_entry_lines[] = $journal_entry_line;
$journal_entry_create['Line'] = $journal_entry_lines;
$journal_entry_receipt_create = QBJournalEntry::create($journal_entry_create);
$journal_entry_receipt_create_result = $dataService->Add($journal_entry_receipt_create);
Without EntityRef its working fine but when I add EntityRef its giving me error "Message: Passed array has no key for 'Value' when contructing an ReferenceType"
Only just came across this problem myself. They did fix this issue but didn't seem to document it at all or tell anyone. Found the fix in the source code. You need to use "JournalEntryEntity" instead of "Entity" under "JournalEntryLineDetail", like so:
'JournalEntryLineDetail' => array(
'PostingType' => "Credit",
'JournalEntryEntity' => array(
'Type' => 'Customer',
'EntityRef' => array(
'value' => "2"
)
),
'AccountRef' => array(
'name' => 'Account Name',
'value' => '1'
),
)
Also I used the FacadeHelper from the V3 of the PHP SDK (I'm not sure if it'll work with the method you were using):
use QuickBooksOnline\API\Facades\FacadeHelper;
...
$journal_entry_receipt_create = FacadeHelper::reflectArrayToObject('JournalEntry', $journal_entry_create);
$journal_entry_receipt_create_result = $dataService->Add($journal_entry_receipt_create);
I know this is probably too late for you OP but hopefully it helps someone else!

Avoid duplicate items when creating contact in Php-Ews

I'm using https://github.com/Garethp/php-ews/ library to access to my public contact folder on Exchange server.
This is how i create a contact.
$api = API::withUsernameAndPassword($server, $user, $pass);
$folder = $api->getFolderByDisplayName('Public', Enumeration\DistinguishedFolderIdNameType::PUBLICFOLDERSROOT);
$contattiTotali = $api->getFolderByDisplayName('Contacts', $folder->getFolderId());
$id=$contattiTotali->getFolderId()->getId();
$api->setFolderId($contattiTotali->getFolderId());
$api->createContacts(array(
'GivenName' => 'Homer',
'Surname' => 'Simpson',
'EmailAddresses' => array(
'Entry' => array('Key' => Enumeration\EmailAddressKeyType::EMAIL_ADDRESS_1, '_value' => 'h.simpson#gmail.com')
),
//Creating multiple entries
'PhoneNumbers' => array(
'Entry' => array(
array('Key' => Enumeration\PhoneNumberKeyType::HOME_PHONE, '_value' => '000'),
array('Key' => Enumeration\PhoneNumberKeyType::BUSINESS_PHONE, '_value' => '111'),
)
),
'PhysicalAddresses' => array(
'Entry' => array(
'Key' => Enumeration\PhysicalAddressKeyType::HOME,
'street' => '123 Street',
'city' => '123 City',
'state' => '123 State',
'countryOrRegion' => '123 Country',
'postalCode' => '12345',
)
),
));
The code, actually, works fine, but if i execute it several times, it duplicates the contact.
Is there a way to check if the contact (email address is good enough) already exists before creating a new one?
The easiest way to telling if a contact already exists with a particular email address is to use the ResolveName operation eg
$request = new EWSType_ResolveNamesType();
$request->UnresolvedEntry = "address#domain.com";
$request->ReturnFullContactData = true;
$return = $ews->ResolveNames($request);
if ($return->ResponseMessages->ResolveNamesResponseMessage->ResponseCode == "NoError") {
return $return->ResponseMessages->ResolveNamesResponseMessage->ResolutionSet->Resolution->Mailbox->EmailAddress;
}

Elastica add documents overrides existing ones

When i try to add new documents to an index type , i loose existing documents which are overwritten by the new added ones . The problem can be related to the id of each added document ??
Here is the code :
$elasticaClient = new \Elastica\Client(array(
'host' => $this->container->getParameter('elastic_host'),
'port' => $this->container->getParameter('elastic_port')
));
$elasticaIndex = $elasticaClient->getIndex('app');
$elasticaIndex->create(
array(
'number_of_shards' => 4,
'number_of_replicas' => 1,
'analysis' => array(
'analyzer' => array(
'indexAnalyzer' => array(
'type' => 'custom',
'tokenizer' => 'standard',
'filter' => array('lowercase', 'mySnowball')
),
'searchAnalyzer' => array(
'type' => 'custom',
'tokenizer' => 'standard',
'filter' => array('standard', 'lowercase', 'mySnowball')
)
),
'filter' => array(
'mySnowball' => array(
'type' => 'snowball',
'language' => 'German'
)
)
)
),
true
);
$elasticaType = $elasticaIndex->getType('type');
$mapping = new \Elastica\Type\Mapping();
$mapping->setType($elasticaType);
$mapping->setParam('index_analyzer', 'indexAnalyzer');
$mapping->setParam('search_analyzer', 'searchAnalyzer');
$mapping->setProperties(array(
'id' => array('type' => 'string'),
'title' => array('type' => 'string'),
'duration' => array('type' => 'string'),
'start' => array('type' => 'string'),
'end' => array('type' => 'string'),
));
// Send mapping to type
$mapping->send();
$documents = array();
foreach($medias as $media) {
$id = uniqid() ;
$documents[] = new \Elastica\Document(
$id,
array(
'id' => $id,
'title' => $media['title'],
'duration' => $media['duration'],
'start' => $media['start'],
'end' => $media['end'],
)
);
}
$elasticaType->addDocuments($documents);
$elasticaType->getIndex()->refresh();
Please i need your help . Thank you
PHP does not recommend using uniqid for this use case. Since you are wanting a random, safe id, let Elasticsearch do it for you. The Elastica Document construct method notes that the id field is optional. So don't pass it and let Elasticsearch issue the id.
Several things
$elasticaIndex->create (....) you only have to enter it once. Index is unique after creating the index that you can comment or generate a different index and other things. I leave an example that works.
class PersistencyElastic
{
private $conection;
public function __construct()
{
$this->conection = new \Elastica\Client(['host' => '127.0.0.1', 'port' => 9200]);
}
public function save($ msg)
{
// $ msg is an array with whatever you want inside
$index = $this->conection->getIndex('googlephotos');
// This is the index I created, it's called googlephotos
// $index->create(array (), true);
$type = $index->getType('googlephotos');
$type->addDocument(new Document (uniqid ('id _', false), $msg, $type, $index));
$index->refresh();
}
}

Cakephp Form is not getting submiited but giving Notice (8): Array to string Coversion, many other Warnings (2)

I am having trouble submitting/saving data to the CakePHP Model. I constructed the form as usual as I always do, but this time I am getting notices and warning an also data is not getting saved. Here is the form I have constructed and method in Controller:
educationaldetails.ctp
<?php
if (empty($Education)):
echo $this->Form->create('Candidate', array('class' => 'dynamic_field_form'));
echo $this->Form->input('CandidatesEducation.0.candidate_id', array(
'type' => 'hidden',
'value' => $userId
));
echo $this->Form->input('CandidatesEducation.0.grade_level', array(
'options' => array(
'Basic' => 'Basic',
'Masters' => 'Masters',
'Doctorate' => 'Doctorate',
'Certificate' => 'Certificate'
)
));
echo $this->Form->input('CandidatesEducation.0.course');
echo $this->Form->input('CandidatesEducation.0.specialization');
echo $this->Form->input('CandidatesEducation.0.university');
echo $this->Form->input('CandidatesEducation.0.year_started', array(
'type' => 'year'
));
echo $this->Form->input('CandidatesEducation.0.year_completed', array(
'type' => 'year'
));
echo $this->Form->input('CandidatesEducation.0.type', array(
'options' => array(
'Full' => 'Full',
'Part-Time' => 'Part-Time',
'Correspondence' => 'Correspondence'
)));
echo $this->Form->input('CandidatesEducation.0.created_on', array(
'type' => 'hidden',
'value' => date('Y-m-d H:i:s')
));
echo $this->Form->input('CandidatesEducation.0.created_ip', array(
'type' => 'hidden',
'value' => $clientIp
));
echo $this->Form->button('Submit', array('type' => 'submit', 'class' => 'submit_button'));
echo $this->Form->end();
endif;
CandidatesController.php
public function educationaldetails() {
$this->layout = 'front_common';
$this->loadModel('CandidatesEducation');
$Education = $this->CandidatesEducation->find('first', array(
'conditions' => array(
'candidate_id = ' => $this->Auth->user('id')
)
));
$this->set('Education', $Education);
// Checking if in case the Candidates Education is available then polpulate the form
if (!empty($Education)):
// If Form is empty then populating the form with respective data.
if (empty($this->request->data)):
$this->request->data = $Education;
endif;
endif;
if ($this->request->is(array('post', 'put')) && !empty($this->request->data)):
$this->Candidate->id = $this->Auth->user('id');
if ($this->Candidate->saveAssociated($this->request->data)):
$this->Session->setFlash('You educational details has been successfully updated', array(
'class' => 'success'
));
return $this->redirect(array(
'controller' => 'candidates',
'action' => 'jbseeker_myprofile',
$this->Auth->user('id')
));
else:
$this->Session->setFlash('You personal details has not been '
. 'updated successfully, please try again later!!', array(
'class' => 'failure'
));
endif;
endif;
}
Here is the screenshot of errors I am getting, Not able to figure out what is happening while other forms are working correctly. looks like something something wrong with view?
This error is coming out because you are not passing the proper arguments to the session->setFlash() method, you are doing like this:
$this->Session->setFlash('You personal details has not been updated successfully, please try again later!!', array(
'class' => 'failure'
));
In docs it is mentioned like:
$this->Session->setFlash('You personal details has not been updated successfully, please try again later!!',
'default', array(
'class' => 'failure'
));
Hi so if i understand :
array(
'CandidatesEducation' => array(
(int) 0 => array(
'candidate_id' => '5',
'grade_level' => 'Basic',
'course' => 'Masters of Computer Application',
'specialization' => '',
'university' => 'Mumbai University',
'year_started' => array(
'year' => '2011'
),
'year_completed' => array(
'year' => '2014'
),
'type' => 'Full',
'created_on' => '2014-11-27 15:44:36',
'created_ip' => '127.0.0.1'
)
)
),
Is your data , and you just need to save this in your candidates_educations table , so in this case i would do :
$this->Candidate->CandidatesEducation->save($this->request->data);
and your $data had to look :
array(
'CandidatesEducation' => array(
'candidate_id' => '5',
'grade_level' => 'Basic',
'course' => 'Masters of Computer Application',
'specialization' => '',
'university' => 'Mumbai University',
'year_started' => array(
'year' => '2011'
),
'year_completed' => array(
'year' => '2014'
),
'type' => 'Full',
'created_on' => '2014-11-27 15:44:36',
'created_ip' => '127.0.0.1'
)
);
the saveAssociated is used when you create your Model AND Model associated , not only your Associated model.
And : i m not sure for year_started and year completed rm of data, it depends of your table schema ; what's the type of year_completed and year_started ?

Categories