Change Item Price when Creating Purchase Order via PHP in Netsuite - netsuite

I am attempting to create open purchase orders in Netsuite during a system migration using Netsuite's PHP Toolkit for 2019_2. I am able to create the purchase order and line items without a problem, but I cannot figure out how to change the item cost on the line item. Setting the line item extended total works, but setting the rate field does not. Can anyone shed any light on why the price is not being set?
I've tried both $poi->item->rate = "5.00"; and $poi->item->rate = 5.00; with no success. The documentation says that this field is a string.
https://www.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2019_2/schema/other/purchaseorderitem.html
$service = new NetSuiteService();
$po = new PurchaseOrder();
$po->tranId = 'PO111111';
$po->tranDate = '2019-03-27T00:00:00';
$po->approvalStatus = new RecordRef();
$po->approvalStatus->internalId = 2;
$po->entity = new RecordRef();
$po->entity->externalId = 'VENDORNAME';
// Create PO Item
$poi = new PurchaseOrderItem();
$poi->item = new RecordRef();
$poi->item->externalId = 'ITEMNUMBER';
$poi->item->rate = "5.00";
$poi->quantity = 10;
$po->itemList = new PurchaseOrderItemList();
$po->itemList->item = array($poi);
$request = new AddRequest();
$request->record = $po;
$addResponse = $service->add($request);
if (!$addResponse->writeResponse->status->isSuccess) {
echo "ADD ERROR";
print_r($addResponse);
} else {
echo "ADD SUCCESS, id " . $addResponse->writeResponse->baseRef->internalId;
}

Set the rate on the purchase order line instead of trying to do it on the item record.
$poi->rate = "5.00";

Related

Is it possible to create a Search in NetSuite SuiteTalk using multiple criteria?

Is it possible to create a Search in SuiteTalk using multiple criteria? I need to search for specific Location and items, using AND/OR logical operators. Something like location = 123 AND (item = 1 OR item = 2).
My code so far returns the result for a given location, but I need only 20-30ish items (not the 1400 i have in the warehouse. The location and the items change in every search, so I need to pass an array of items as filter/criteria.
My code so far
$searchValue = new RecordRef();
$searchValue->type = 'location';
$searchValue->internalId = 123;
$searchMultiSelectField = new SearchMultiSelectField();
setFields($searchMultiSelectField, array(
'operator' => 'anyOf',
'searchValue' => $searchValue
));
$locationSearchBasic->internalId = $searchMultiSelectField;
$itemSearch->inventoryLocationJoin = $locationSearchBasic;
$itemSearchAdvance->criteria = $itemSearch;
$request = new SearchRequest();
$request->searchRecord = $itemSearchAdvance;
$searchResponse = $service->search($request);
It is possible to have multiple criteria using AND, but as far as I know it is not possible to use OR criteria in a search. An example of the former would look something like this:
$searchValue = new RecordRef();
$searchValue->type = 'location';
$searchValue->internalId = 123;
$searchMultiSelectField = new SearchMultiSelectField();
setFields($searchMultiSelectField, array(
'operator' => 'anyOf',
'searchValue' => $searchValue
));
$locationSearchBasic->internalId = $searchMultiSelectField;
$itemSearch->inventoryLocationJoin = $locationSearchBasic;
// Add an item criteria
$searchStringField = new SearchStringField();
$searchStringField->searchValue = 1;
$itemSearchBasic = new ItemSearchBasic();
$itemSearchBasic->itemId = $searchStringField;
$itemSearch->basic = $itemSearchBasic;
$itemSearchAdvance->criteria = $itemSearch;
$request = new SearchRequest();
$request->searchRecord = $itemSearchAdvance;
$searchResponse = $service->search($request);

"Lot/serial nbr ('anyNumber') can not found in the system", why am i getting this?

"Lot/serial nbr ('anyNumber') can not found in the system", why am i getting this when transfer inventory from a location to another?
1) Transferred inventory from SHIPMENT location/warehouse to another location warehouse.
2) then transferring again from above location warehouse to another warehouse/location. then got error.
INTransferEntry transferGraph = PXGraph.CreateInstance<INTransferEntry>();
INRegister reg = new INRegister();
reg.SiteID = lotDetail.WarehouseID;
reg.ToSiteID = distribution.ToWarehouseID;
reg.TransferType = Order.Current.TranType;
reg.DocType = INDocType.Transfer;
reg.TranDate = DateTime.Now;
reg.TotalQty = distribution.Qty;
reg = transferGraph.transfer.Insert(reg);
INTran tran = new INTran();
tran.INTransitQty = distribution.Qty;
tran.InventoryID = Order.Current.InventoryID;
tran.ToLocationID = distribution.ToLocationID;
tran.ToSiteID = distribution.ToWarehouseID;
tran.TranType = INTranType.Transfer;
tran.InvtMult = INTranType.InvtMult(tran.TranType);
tran.Qty = distribution.Qty;
tran.ReasonCode = distribution.ReasonCode;
tran.SiteID = lotDetail.WarehouseID;
tran.LocationID = lotDetail.LocationID;
tran.TranDesc = distribution.Description;
tran.LotSerialNbr = lotDetail.LotSerNumVal;
tran = transferGraph.transactions.Insert(tran);
You need to look at the INTranSplit DAC, it links the Lot Tracking with the INTran DAC to manage the existing Lots linked to the INItem

Disable/enable an input field

Using this sample code, I am trying to enable/disable the field "arrdatfrom". However, once this text field has been DISABLED, i cannot get it to be re-ENABLED. The function below gets executed when the user clicks a "Refresh" button. I have built this little demo just to prove that I have tried many ways to do this. Any ideas?
function showBooking() {
var d = new Date()
formvals.arrdatefrom = document.getElementById("arrdatfrom").value
formvals.arrdatethru = document.getElementById("arrdatthru").value
formvals.depdatefrom = document.getElementById("depdatfrom").value
formvals.depdatethru = document.getElementById("depdatthru").value
formvals.bookname = document.getElementById("bookname").value
formvals.peakroomfrom = document.getElementById("peakroomfrom").value
formvals.peakroomthru = document.getElementById("peakroomthru").value
formvals.peakattendfrom = document.getElementById("peakattendfrom").value
formvals.peakattendthru = document.getElementById("peakattendthru").value
alert (' ngs.hta ready to enable')
document.getElementById("arrdatfrom").enabled = 'true'
alert ('ngs.hta in showBooking!! disable. ')
document.getElementById("arrdatfrom").disabled = 'true'
...
There is no property .enabled. To re-enable a disabled element, set .disabled = false.

DirectorySearcher.Filter which queries active directory to return upcoming events of the current week

I am trying to get all birthdays and anniversaries which fall under current week. I am using Directory Searcher and LDAP. I am new to LDAP and I am using the below code:
string _path = "LDAP:";
System.DirectoryServices.DirectoryEntry entry = new System.DirectoryServices.DirectoryEntry(_path);
DirectorySearcher ds = new DirectorySearcher(entry);
string month = DateTime.Now.Month.ToString();
string day = DateTime.Today.Day + numDays.ToString();
ds.Filter = "(&(objectClass=user)(description=" + month + "\\" + day +"))";
SortOption option = new SortOption("description", System.DirectoryServices.SortDirection.Ascending);
ds.Sort = option;
DataSet dSet = new DataSet();
DataTable dTable = new DataTable("Events");
dTable.Columns.Add("birthday");
foreach (System.DirectoryServices.SearchResult resEvent in ds.FindAll())
{
System.DirectoryServices.DirectoryEntry de1 = resEvent.GetDirectoryEntry();
DataRow dRow = dTable.NewRow();
if (de1.Properties["description"].Value != null)
{
dRow["birthday"] = de1.Properties["description"].Value.ToString();
dTable.Rows.Add(dRow);
}
}
dSet.Tables.Add(dTable);
return dSet;
Are your events stored under the user's description attribute?
Not much detailas to what your attribute values look like.
You are trying to user c# which I do not have access to, but from a LDAP Query, this works:
(&(objectClass=user)(description=09/15*))
-jim

Two Web Parts connection doesn't work when set programmatically

I've a SharePoint 2010 page with a list. The list has several items and a field named "Department" and must filter items based on user's department value retrieved from user profile.
To do this I've created a feature which upon activation adds UserContextFilterWebPart to the page and makes connection between UserContextFilterWebPart and XsltListViewWebPart. After the feature is activated I can see in the page design mode that connection is established but the list gets empty. Then I open web part's menu, choose "Connections" then "Send Filter Values To" and click "List1". When dialog appears I do nothing but only click "Finish" button and it begins to work fine. Can anybody please explain me why the connection begins to work only if I do that manual extra action? What must be done to fix?
I tried different way when List.Views[0].Query property is set to appropriate CAML query and it also works fine. But I'm told that it's not a good approach because of performance and parallel tasks issues. Is it really bad course of action?
Below is the code for 2 different approaches.
Thanks in advance!
1-s variant with UserContextFilterWebPart:
SPSite Site = new SPSite(URL);
SPWeb Web = Site.OpenWeb();
SPLimitedWebPartManager WPM = Web.GetLimitedWebPartManager(URL, PersonalizationScope.Shared);
XsltListViewWebPart List = WPM.WebParts[0] as XsltListViewWebPart;
UserContextFilterWebPart UCFWP = new UserContextFilterWebPart();
UCFWP.Title = "Current User Filter";
UCFWP.AllowEdit = true;
UCFWP.FilterName = "Current User";
UCFWP.SendEmptyWhenNoValues = true;
UCFWP.AllowClose = true;
UCFWP.ExportMode = WebPartExportMode.All;
UCFWP.AllowConnect = true;
UCFWP.AllowHide = true;
UCFWP.ProfilePropertyName = "Department";
UCFWP.ValueKind = UserContextFilterValueKind.ProfileValue;
UCFWP.ZoneID = "Main";
WPM.AddWebPart(UCFWP, UCFWP.ZoneID, 1);
WPM.SaveChanges(UCFWP);
ConsumerConnectionPointCollection consumerConnections = WPM.GetConsumerConnectionPoints(List);
ConsumerConnectionPoint addConsumerConnPoint = consumerConnections["DFWP Filter Consumer ID"];
ProviderConnectionPointCollection providerConnections = WPM.GetProviderConnectionPoints(UCFWP);
ProviderConnectionPoint addProviderConnPoint = providerConnections["ITransformableFilterValues"];
TransformableFilterValuesToParametersTransformer trans = new TransformableFilterValuesToParametersTransformer();
trans.ConsumerFieldNames = new string[] { "Department" };
trans.ProviderFieldNames = new string[] { "Department" };
SPWebPartConnection newConnection = WPM.SPConnectWebParts(UCFWP, addProviderConnPoint, List, addConsumerConnPoint, trans);
WPM.SPWebPartConnections.Add(newConnection);
2-nd variant with CAML query (intended to be used not in a feature but in a web part):
SPSite Site = new SPSite(URL);
SPWeb Web = Site.OpenWeb();
SPLimitedWebPartManager WPM = Web.GetLimitedWebPartManager(URL, PersonalizationScope.Shared);
XsltListViewWebPart List = WPM.WebParts[0] as XsltListViewWebPart;
SPUser CurrentUser = Web.CurrentUser;
SPServiceContext context = SPServiceContext.GetContext(Site);
UserProfileManager upm = new UserProfileManager(context, false);
UserProfile up = upm.GetUserProfile(CurrentUser.RawSid);
String UserDepartment = up["Department"].Value.ToString();
SPView ListView = Web.Lists["List1"].Views[0];
ListView.Query = "<Where><Eq><FieldRef Name='Department' /><Value Type='Text'>" + UserDepartment + "</Value></Eq></Where>";
ListView.Update();
I had a similar problem of connecting two web parts. I found the answer here: http://kvdlinden.blogspot.dk/2011/02/programmatically-connect-two.html
Note that that post describes how to do it with two XsltListViewWebParts. In order to use it in your case I suggest that you:
Create the connection manually,
Use PowerShell to get a SPLimitedWebPartManager for the page,
Use the manager to iterate through the manager.SPWebPartConnections,
And find the ProviderConnectionPointID for your connection,
Use that ID in the code shown in the post.
Also remember to setup the transformer - you can find this also from the SPWebPartConnections.
Next time you activate your feature you should have a connection equal to the one you made by hand.

Resources