John Davidson

NetSuite PHP Toolkit Time Entry Search

0 comments
Message:


<?php
// Token-based Authentication
require 'vendor/autoload.php';

use NetSuite\NetSuiteService;


$config = array(
// required -------------------------------------
"endpoint" => "2019_1",
"host" => "https://webservices.netsuite.com",
"email" => "[email protected]",
"password" => "Mypassword",
"role" => "12345",
"account" => "7654321",
"app_id" => "XXXXXXX-XXXXX-XXXXX-XXXX-XXXXXXXXX",
);
$service = new NetSuiteService($config);
$service->setSearchPreferences(true, 20);

use NetSuite\Classes\SearchDateField;
use NetSuite\Classes\TimeEntrySearch;
use NetSuite\Classes\TimeEntrySearchBasic;
use NetSuite\Classes\TimeEntrySearchAdvanced;
use NetSuite\Classes\SearchRequest;



//Search Date
$SearchField = new SearchDateField();
$SearchField->searchValue = '2021-05-01T00:16:11+00:00';
$SearchField->operator = "after";
$ItemSearchBasic = new TimeEntrySearchBasic();
$ItemSearchBasic->lastModified = $SearchField;

$ItemSearch = new TimeEntrySearch();
$ItemSearch->basic = $ItemSearchBasic;

$search = new TimeEntrySearchAdvanced();
$search->columns = "TimeEntrySearchRow";
$search->criteria = $ItemSearch;

$request = new SearchRequest();
$request->searchRecord = $search;

$searchResponse = $service->search($request);
echo "<pre>";print_r($searchResponse);die();
if (!$searchResponse->searchResult->status->isSuccess) {
echo "SEARCH ERROR";
} else {
echo "SEARCH SUCCESS, records found: " . $searchResponse->searchResult->totalRecords . "\n";
$records = $searchResponse->searchResult->searchRowList->searchRow;

foreach ($records as $record) {
echo "Name: " . $record->basic->name->searchValue . "\n";
}

}
?>

I'm trying to get the last Time Entry in NetSuite filter by lastModified operator "After", I don't know what I'm doing wrong.


The error message is: -> The ''Timesheets'' feature is not enabled in your NetSuite account.


What do I need to activate?



My Answer:
To search for time entries in NetSuite using the PHP Toolkit, you can use the `TimeEntrySearchBasic` object. Here is an example code snippet to perform a time entry search:

php
require_once 'NetSuiteService.php';

$service = new NetSuiteService();

$search = new TimeEntrySearchBasic();
$search->type = new SearchEnumMultiSelectField();
$search->type->operator = 'anyOf';
$search->type->searchValue = array('_timeEntry');

$request = new SearchRequest();
$request->searchRecord = $search;

$searchResponse = $service->search($request);

if (!$searchResponse->searchResult->status->isSuccess) {
echo "Search failed: " . $searchResponse->searchResult->status->statusDetail[0]->message;
} else {
$timeEntries = $searchResponse->searchResult->recordList;

foreach ($timeEntries as $timeEntry) {
// Process each time entry
echo "Time Entry ID: " . $timeEntry->internalId . "\n";
echo "Date: " . $timeEntry->date->searchValue . "\n";
echo "Hours: " . $timeEntry->hours->searchValue . "\n";
// Add more fields as needed
}
}


In this code snippet, we first create a `TimeEntrySearchBasic` object and set the search criteria (in this case, searching for all time entries). We then create a `SearchRequest` object and set the searchRecord to our `TimeEntrySearchBasic` object. We then call the `search` method on the `NetSuiteService` object to perform the search.

If the search is successful, we iterate through the results and process each time entry as needed. You can add more fields to the output as required for your use case.

Rate this post

4 of 5 based on 1674 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us