====== Convert Lead Webservice ====== Usage example of convert lead web service in order to convert an existing Leads into Accounts, Contacts & Opportunity using Webservice. Important points to note before using the following code: * Check table vtiger_ws_entity to know the "id" (Webservice module ID) of the "Leads" module. Ensure that the Lead ID passed to vtws_convertleads function is in 'x' format. * Following example uses standard vtwsclib library. * Sample code:doLogin('admin', 'KpS9EjNz16JtPmoe'); if(!$login) return 0; return $client; } function vtws_convertleads($recordid){ $client = vtws_login(); if ($client <> 0){ $recordInfo = $client->doRetrieve($recordid); $wasError= $client->lastError(); if($wasError) { return $wasError['code'] . ':' . $wasError['message']; } if($recordInfo) { $client1 = vtws_login(); $convert_lead_array = array(); $convert_lead_array['leadId'] = $recordInfo['id']; $convert_lead_array['assignedTo'] = $recordInfo['assigned_user_id']; $convert_lead_array['entities']['Accounts']['create']=true; $convert_lead_array['entities']['Accounts']['name']='Accounts'; $convert_lead_array['entities']['Accounts']['accountname'] = $recordInfo['company']; $convert_lead_array['entities']['Accounts']['industry']=$recordInfo['industry']; $convert_lead_array['entities']['Potentials']['create']=true; $convert_lead_array['entities']['Potentials']['name']='Potentials'; $convert_lead_array['entities']['Potentials']['potentialname']=$recordInfo['company']; $convert_lead_array['entities']['Potentials']['closingdate']= date("Y-m-d", strtotime("+1 week Saturday")); $convert_lead_array['entities']['Potentials']['sales_stage']= 'Prospecting'; $convert_lead_array['entities']['Potentials']['amount']= 0; $convert_lead_array['entities']['Contacts']['create']=true; $convert_lead_array['entities']['Contacts']['name']='Contacts'; $convert_lead_array['entities']['Contacts']['lastname']=$recordInfo['lastname']; $convert_lead_array['entities']['Contacts']['firstname']=$recordInfo['firstname']; $convert_lead_array['entities']['Contacts']['email']=$recordInfo['email']; $convert_lead_json = json_encode($convert_lead_array); $response = $client1->doInvoke('convertlead', array('element'=>$convert_lead_json)); $wasError = $client1->lastError(); if($wasError) { return $wasError['code'] . ':' . $wasError['message']; } else { return 1; } } }else{ return 'Login failed'; } } $d = '2x21022'; echo vtws_convertleads($d); ?> ^Purpose:|Permits the conversion of a lead into an account, contact and potential. This service is used by the application itself when converting leads.| ^Profile:|convertlead($entityvalues): Map| ^Send as:|POST| ^Parameters:| id: $entityvalues is an array. Consult the modules/Leads/LeadConvertToEntities.php to see an example.| ^Returns:|Array with all the information of the new objects created| ^URL Format:|http://vtiger_url/webservice.php?operation=deleteUser&sessionName=[session id]| [[https://discussions.vtiger.com/index.php?p=/discussion/166499/usage-example-of-convert-lead-webservice|Thanks Ashutosh]] You can also find an [[https://github.com/tsolucio/coreBOSwsDevelopment/blob/master/testcode/470_convertLead.php|example in the coreBOS Webservice development]] tool. By setting $convert_lead_array['entities'][__Contacts|Accounts|Potential__]['create'] to **false** you can avoid creating a record in that module. By default, a Lead is Converted into a Contact, but you can indicate the module you want to have the Lead values transferred to using the variable **//transferRelatedRecordsTo//** $convert_lead_array['entities']['transferRelatedRecordsTo'] = 'Accounts'; If you indicate that no Contact should be created the Lead values will be transferred to the Account. If you indicate that neither a Contact nor an Account should be created the process will fail with a web service exception. By default, the process will search for an existing Account with the same company name and relate the new records with this Account. This is done to avoid duplicates. You can override this behavior by assigning a value to the meta-variable **//forcecreate//** like this: $convert_lead_array['entities'][Accounts]['forcecreate'] = true; Be careful as this will easily create duplicate account names and you won't be able to edit them unless you set the global variable **//Accounts_BlockDuplicateName//** to false. ---- [[:en:devel:corebosws:portallogin|Next: Portal user login]] | [[en:devel:corebosws:tableofcontents|Table of Contents]] ----