Current Path :
/
home
/
zrcdevco
/
www
/
zrc-email-program
/
Or
Select Your Path :
Upload File :
New :
File
Dir
/home/zrcdevco/www/zrc-email-program/saved_search_ns_hs.php
<?php require_once '../PHPToolkit/NetSuiteService.php'; $service = new NetSuiteService(); //print_r($service); //$search = new CustomRecordSearchAdvanced(); $search = new CustomerSearchAdvanced(); $search->savedSearchId = "313"; $request = new SearchRequest(); $request->searchRecord = $search; print_r($request); $searchResponse = $service->search($request); if (!$searchResponse->searchResult->status->isSuccess) { echo "SEARCH ERROR"; print_r($searchResponse); } else { echo "SEARCH SUCCESS, records found: " . $searchResponse->searchResult->totalRecords . "\n"; $records = $searchResponse->searchResult->searchRowList->searchRow; // print_r($records[0]); // print_r($records[1]); /************************************************* * * Scan the records to find the following: * - Open Records * - Click Records that did not unsubscribe. * send these records to Hubspot CRM. * Fields for Hubspot * - company * - email * - first name * - last name * - phone * - website * to Store other attributes such as project, project role, ... we will need to create a Custom Object in Hubspot * https://developers.hubspot.com/docs/api/crm/crm-custom-objects *************************************************/ // Add a date stamp to the file name // Array to set Project Role to a text field $project_role = array("Architect"=>"1", "Structural Engineer"=>"2", "General Contractor"=>"3", "Structural Steel"=>"4"); $processDate = date("Y-m-d"); $fileDate = str_replace('-','',$processDate); $myFile = fopen("newlead.".$fileDate."txt", "w") or die("Unable to open file!"); foreach ($records as $record) { print_r($record); //echo "Name: " . $record->basic->altName[0]->searchValue . "\n"; //echo "Campaign Response: " . $record->campaignResponseJoin->response[0]->searchValue . "\n"; $response = $record->campaignResponseJoin->response[0]->searchValue; // check for response if ($response == "_opened") { // For users that Open and Email output search results + // Lookup Company Name, Project Name, Project Role, Project Price, LEED Certification // use this program to lookup company name, project name and project role. // ProjectRole (custentityprojectrole) is always the [3] element in the customField Array - this will also need to lookup the Role list // Project Name (custentityprojectname) is always the [6] element in the customField Array - we can pull the searchValue object element, // we are not saving project price yet // https://www.trionia.com/ZRC/CMDTest/NS-EmailProgram/contact_search_ver1.php $txt=""; // initialize output $name = $record->basic->altName[0]->searchValue; $name = explode( ',', $record->basic->altName[0]->searchValue); // first name (end of the name string) $txt = array_pop($name).","; // last (start of the name string) $txt .= array_shift($name).","; $txt .= $record->basic->email[0]->searchValue.","; $txt .= $record->basic->phone[0]->searchValue.","; // website URL (end of the email string) $txt .= array_pop(explode( '@', $record->basic->email[0]->searchValue)).","; // Property Role $role = array_search($record->basic->customFieldList->customField[3]->searchValue->internalId, $project_role); // $key = 2; $txt .= $role.","; // Property Name $txt .= $record->basic->customFieldList->customField[6]->searchValue."\n"; echo($txt); fwrite($myFile, $txt); } } fclose($myFile); } ?>