PHP NetSuite - Advanced Search with criterion - php

I have PHP code for Advanced Search items in NetSuite,
but I don't know how I can combine to my search - filtering by item name.
My code is:
$service = new NetSuiteService($config);
$service->setSearchPreferences(true, $page_size, true);
$savedSearchId = '###';
$searchAdvanced = new ItemSearchAdvanced();
setFields($searchAdvanced, array('savedSearchScriptId'=>$savedSearchId));
$request = new SearchRequest();
$request->searchRecord = $searchAdvanced;
$results = $service->search($request);
I want to combine a criteria

Here's sample code I found to get inventory details using Item internal id as a filter. You can reference Suite Answer 90401, 37585, and 25066.
<?php
require_once '../PHPToolkit/NetSuiteService.php';
$service = new NetSuiteService();
// formulate the criteria
$itemRecord = new RecordRef();
$itemRecord--->internalId = 140;
$itemMultiSelect = new SearchMultiSelectField();
$itemMultiSelect->operator = 'anyOf';
$itemMultiSelect->searchValue = $itemRecord;
$itemSearchBasic = new ItemSearchBasic();
$itemSearchBasic->internalId = $itemMultiSelect;
$criteria = new ItemSearch();
$criteria->basic = $itemSearchBasic;
// formulate the resulting columns
$searchRowBasic = new ItemSearchRowBasic();
$searchRowBasic->itemId = new SearchColumnStringField(); // Item Name/Number in UI
$searchRowBasic->internalId = new SearchColumnSelectField(); // Internal ID in UI
$searchRowBasic->location = new SearchColumnSelectField(); // Location (Main section of Inventory Item) in UI
$searchRowBasic->inventoryLocation = new SearchColumnSelectField(); // Location column in Locations tab (Inventory Item) in UI
$searchRowBasic->locationQuantityOnHand = new SearchColumnDoubleField();// Quantity on Hand column in Locations tab (Inventory Item) in UI
$columns = new ItemSearchRow();
$columns->basic = $searchRowBasic;
// item search advanced
$search = new ItemSearchAdvanced();
$search->criteria = $criteria;
$search->columns = $columns;
$request = new SearchRequest();
$request->searchRecord = $search;
$searchResponse = $service->search($request);
if (!$searchResponse->searchResult->status->isSuccess) {
echo "SEARCH ERROR";
} else {
echo "SEARCH SUCCESS, records found: " . $searchResponse->searchResult->totalRecords ;
}
?>

Related

How do I get the serialized inventory item by the inventory id in NetSuite api with PHP?

Here is the situation, I'm trying to get the Serialized Inventory Item based on the id (https://xxx.app.netsuite.com/app/common/item/item.nl?id=522216), however, when I tried the following code:
$search = new TransactionSearchBasic();
$type = new SearchEnumMultiSelectField();
$type->operator = 'anyOf';
$type->searchValue = array('serializedInventoryItem');
$search->type = $type;
$invetoryRef = new RecordRef();
$invetoryRef->internalId = '522216';
$params = new SearchMultiSelectField();
$params->operator = 'anyOf';
$params->searchValue = array($invetoryRef);
$search->serializedInventoryItem = $params;
$request = new SearchRequest();
$request->searchRecord = $search;
$searchResponse = $service->search($request);
However, the response that I'm getting the following error:
The field type's enum value is invalid for this search.
Why would I be getting that error message?
Thank you,
Kevin Davis

Netsuite Item Fulfillment Invalid Line Items

I'm trying to set a SalesOrder to fulfilled using the PHP Netsuite Api but I keep getting the following error:
VALID_LINE_ITEM_REQD - You must have at least one valid line item for
this transaction.
I'm using the https://github.com/ryanwinchester/netsuite-php library.
I have the following so far. I've tried using the Initialise methods as well that I've seen in some examples, but they all seem to give the same error. We're using Advanced Inventory Management if that helps.
$itemFulfillment = new ItemFulfillment();
// Sales Order
$itemFulfillment->createdFrom = new RecordRef();
$itemFulfillment->createdFrom->internalId = <SALES_ORDER_ID>;
$itemFulfillment->shipStatus = ItemFulfillmentShipStatus::_shipped;
// Customer
$itemFulfillment->entity = new RecordRef();
$itemFulfillment->entity->internalId = <CUSTOMER_ID>;
// List
$fullfillmentList = new ItemFulfillmentItemList();
$fullfillmentList->replaceAll = true;
foreach($salesOrder->itemList->item as $saleItem) {
$item = new ItemFulfillmentItem();
$item->location = new RecordRef();
$item->location->internalId = 4;
$item->item = new RecordRef();
$item->item->internalId = $saleItem->item->internalId;
$item->itemIsFulfilled = true;
$item->itemReceive = true;
$item->quantity = $saleItem->quantity;
$item->orderLine = $saleItem->line;
// Department Reference
$departmentRec = new RecordRef();
$departmentRec->internalId = 5;
$item->department = $departmentRec;
$fullfillmentList->item[] = $item;
}
$itemFulfillment->itemList = $fullfillmentList;
$request = new AddRequest();
$request->record = $itemFulfillment;
$client->add($request);
Any help would be great. :)
Transforming a Sales Order to a
Cross-Subsidiary Item Fulfillment Record will return a
"VALID_LINE_ITEM_REQD >
You must have at least one valid line item for this transaction" error if we did not specify an inventoryLocation in the defaultValue parameter.
function createIF(soId, invLocation) {
var itemFulfillment = record.transform({
fromType: record.Type.SALES_ORDER,
fromId: soId,
toType: record.Type.ITEM_FULFILLMENT,
defaultValues: {
inventorylocation: invLocation
}
});
/**
* You can insert other script logic here
*/
var ifID = itemFulfillment.save();
return ifID;
}
make sure the item is in inventory
make sure the item is available to your subsidiary
make sure you are committing sublists correctly, if applicable
dump $saleItem to see whats in it to make sure noting is null

How to post an event directly to another user's calendar

i want To post an event directly to another user's calendar with jamesiarmes/php-ews but in example i have find only how to make it with invitation.
I have admin account so i can write in athers user's post calendar directly.
i don't understant a lot because i'm new in ews so thx for any help.
// Replace this with your desired start/end times and guests.
$start = new DateTime('tomorrow 4:00pm');
$end = new DateTime('tomorrow 5:00pm');
$guests = array(
array(
'name' => 'Homer Simpson',
'email' => 'hsimpson#example.com',
),
array(
'name' => 'Marge Simpson',
'email' => 'msimpson#example.com',
),
);
// Set connection information.
$host = '';
$username = '';
$password = '';
$version = Client::VERSION_2016;
$client = new Client($host, $username, $password, $version);
// Build the request,
$request = new CreateItemType();
$request->SendMeetingInvitations = CalendarItemCreateOrDeleteOperationType::SEND_ONLY_TO_ALL;
$request->Items = new NonEmptyArrayOfAllItemsType();
// Build the event to be added.
$event = new CalendarItemType();
$event->RequiredAttendees = new NonEmptyArrayOfAttendeesType();
$event->Start = $start->format('c');
$event->End = $end->format('c');
$event->Subject = 'EWS Test Event';
// Set the event body.
$event->Body = new BodyType();
$event->Body->_ = 'This is the event body';
$event->Body->BodyType = BodyTypeType::TEXT;
// Iterate over the guests, adding each as an attendee to the request.
foreach ($guests as $guest) {
$attendee = new AttendeeType();
$attendee->Mailbox = new EmailAddressType();
$attendee->Mailbox->EmailAddress = $guest['email'];
$attendee->Mailbox->Name = $guest['name'];
$attendee->Mailbox->RoutingType = RoutingType::SMTP;
$event->RequiredAttendees->Attendee[] = $attendee;
}
// Add the event to the request. You could add multiple events to create more
// than one in a single request.
$request->Items->CalendarItem[] = $event;
$response = $client->CreateItem($request);
// Iterate over the results, printing any error messages or event ids.
$response_messages = $response->ResponseMessages->CreateItemResponseMessage;
foreach ($response_messages as $response_message) {
// Make sure the request succeeded.
if ($response_message->ResponseClass != ResponseClassType::SUCCESS) {
$code = $response_message->ResponseCode;
$message = $response_message->MessageText;
fwrite(STDERR, "Event failed to create with \"$code: $message\"\n");
continue;
}
// Iterate over the created events, printing the id for each.
foreach ($response_message->Items->CalendarItem as $item) {
$id = $item->ItemId->Id;
fwrite(STDOUT, "Created event $id\n");
}
}
You define the attendees but miss the account where you want to create the event in:add this code before the $response
...
$request->Items->CalendarItem[] = $event;
//following lines are missing
$lsEmail = 'some#email.de';
$request->SavedItemFolderId = new TargetFolderIdType();
$request->SavedItemFolderId->DistinguishedFolderId = new DistinguishedFolderIdType();
$request->SavedItemFolderId->DistinguishedFolderId->Id = self::DISTINGUISHED_FOLDER_ID;
$request->SavedItemFolderId->DistinguishedFolderId->Mailbox = new EmailAddressType();
$request->SavedItemFolderId->DistinguishedFolderId->Mailbox->EmailAddress = $lsEmail;
// here your code continues
$response = $client->CreateItem($request);
...

How to create a new AssemblyItem in Netsuite PHP toolkit?

I am trying to send the order info from Woocommerce into Netsuite as a sale order, when creating a new order. In order to create a new sale order by PHP toolkit, it is necessary for me to create Assembly Items first.
Is there a way to create a new Item using PHP-toolkit?
Here is a PHP code snippet for creating a new Item myself.
$service = new NetSuiteService();
$ai = new AssemblyItem();
// Rustica Group Item Form - 20
$ai->customForm = new RecordRef();
$ai->customForm->internalId = 20;
$ai->memberList = new ItemMemberList();
$item_member = array();
$itemMember = new ItemMember();
$itemMember->internalId = 186625;
$item_member[] = $itemMember;
$ai->memberList->itemMember = $item_member;
$ai->itemId = 'Hardware' . $data['itemId'];
$ai->displayName = $data['displayName'];
$ai->vendorName = '';
$ai->cost = $data['price'];
$ai->isTaxable = $data['taxable'];
$ai->description = $data['description'];
$request = new AddRequest();
$request->record = $ai;
$addResponse = $service->add($request);
print_r($addResponse);
if (!$addResponse->writeResponse->status->isSuccess) {
return "ADD ERROR";
} else {
return $addResponse->writeResponse->baseRef->internalId;
}
There is no internalid field for ItemMember. Look at the schema
Should look like this...
$itemMember = new ItemMember();
$itemMember->item = new RecordRef();
$itemMember->item->internalId = 186625;
You're missing taxSchedule too..not sure if you are confusing that with isTaxable
$ai->taxSchedule = new RecordRef();
$ai->taxSchedule->internalId = 1; //whatever tax schedule you're using
You should pre-store the item of the product before saving the product that you want to send from Woocommerce into Netsuite.
If you store the item on netsuite, they will return the internal_id of the item.
Then, you can save the item with internal id that they return.

Sending WooCommerce order to NetSuite

I'm attempting to take an order from WooCommerce using the Rest API, and add that information into NetSuite as a Sales Order. I can successfully grab the order information from WooCommerce, but I am unsuccessful when adding the order into NetSuite using the PHPToolkit. Here is what I have so far:
<?php
/*
* Add a customer to Netsuite.
*
* paramtypesmap
*
*/
require_once 'includes/functions.php';
// create array of fields
$itemArr = array();
$i = 0;
$service = new NetSuiteService();
$salesOrder = new SalesOrder();
$salesOrder->entity = new RecordRef();
$salesOrder->entity->internalId = 512;
$salesOrder->entity->type = 'customer';
$salesOrder->shipDate = formatDate('2014-10-06T07:12:57.000-07:00');
$service = new NetSuiteService();
$service->setSearchPreferences(false, 1000);
$siteCategory = new SearchMultiSelectField();
$siteCategory->operator = "anyOf";
$siteCategory->searchValue = array('internalId' => 512);
$search = new ItemSearchBasic();
$search->internalId = $siteCategory;
$request = new SearchRequest();
$request->searchRecord = $search;
$searchResponse = $service->search($request);
$products = $searchResponse->searchResult->recordList->record;
$salesOrder->itemList = new SalesOrderItemList();
$item = new SalesOrderItem();
$item->item = new RecordRef();
$item->item->internalId = 531;
$item->quantity = 1;
//removeEmpty($item->item);
//removeEmpty($item);
$item->price = new RecordRef();
$item->price->internalId = 1;
$item->amount = 55.3;
$salesOrder->itemList->item=array(0=>$item);
//Equivalent too print_r
pr($item);
//Equivalent too print_r
pr($salesOrder);
removeEmpty($salesOrder);
$request = new AddRequest();
$request->record = $salesOrder;
//$service->setFields($purchaseOrderFields);
$response = $service->add($request);
if (!$response->writeResponse->status->isSuccess) {
echo getErrors($response->writeResponse);
} else {
echo success($response->writeResponse->baseRef->internalId);
}
?>
I'm just trying to work from the ground up to see what fields are required and how to build them, however I keep getting this error when ran:
Please choose a child matrix item
I have spent the last couple of days attempting to try some Google Fu on the problem, but with my luck found nothing. Can anyone help me with this?
Based from the error message, you are trying to submit a Parent Matrix Item instead of the child. Verify it by checking the Item Record with internal id 531.
The best way to achieve correct internal ids is to import Matrix Items directly from NetSuite into WooCommerce as variable products. Assigning the internal id to each variation.

Categories