Search Filter for one level down in SuiteScript - netsuite

Basically, what I need to do is get at the Billing Transactions:Internal Id field in a script for searching.
I have a saved Transaction search, where type = Purchase Order. I need to get the PO internalid AND the Billing Transaction: Internal Id. The saved search is fine.
Because in script the nlapiSearchRecord can only get one record, and I have over 9,000 rows, I am doing a loop where I am adding a filter of internalid >= the last internalId of the previous execution (1,000 rows). However, I need the filter for this search to be on the Billing Transaction:Internal Id NOT the PO Internal ID.
What "field" can I use in the nlobjSearchFilter creation to get the Billing Transaction:Internal Id?

Using the NetSuite Records Browser, if you check the Search Filters section for Purchase Orders, there is a filter there called billingtransaction that you can use. There is also a Search Column of the same name, so you can also retrieve that in your results.
Another option, if you have a saved search and are comfortable with your script executing saved searches, you can simply pass the search ID to nlapiSearchRecord or nlapiCreateSearch to execute the saved search or modify it then execute it, respectively. We typically avoid doing this in our code because any Administrator can modify a Saved Search, even Private ones, but it is an option nonetheless.

Related

Netsuite Custom Sublist Saved Search Filtered by Free-Form Text Field?

I am familiar with creating custom sublists on NetSuite forms by creating a Saved Search and on the Available Filters subtab, adding at least one available filter from a List/Record type field. If you don't use a List/Record type field as the first Available Filter, the saved search is not available to assign as a sublist.
Is there a workaround to add a save search as a custom sublist filtered by a Free-Form text field? Is there a way to achieve this using SuiteScrpt? Specifically, I want to use the otherrefnum field on sales transactions to filter a search that shows all other transactions with that otherrefnum. Any help is very much appreciated!
Saved search as custom list can be added to a form only with a List/Record field, since this is the Primary/Foreign key that the join is based on.
I think that the only way to add a saved search sublist that will be filtered by a free-form text is via a script.
You can do it by manually performing the search and generating the sublist on the beforeLoad of the relevant user event.
Just keep in mind that performing searches that are filtered by free text are very heavy and might have significant impact on performance and the loading time of the form.
I can create a saved search and make it a sublist and search on OtherRefNum
In the search definition add criteria to filter to the mainline.
For the available filters select PO/Check ID
go to a customer and select that search for the sublist view.
here's the bug: Now refresh the page and your filter is available.
The results are automatically filtered to transactions for that customer.
If you are trying to make a general search for OtherRefNum do you know that you can just enter it into Netsuite's global search (top of the page) and all transactions that have that value will be returned?
There is no speed penalty for doing a free text search on otherrefnum. It is an indexed field and searches on it are very fast.

Netsuite System Notes for Contract Items

In NetSuite, I am trying to create a Saved Search report that shows field changes to individual contract line items. I will be using this report to reconstruct historical data, including pricing and quantities.
I have a Transaction Saved Search that shows me each contract and every contract line item. I have tried to include System Notes fields to pull in the field history, but it is only able to show me System Notes for the overall contract record (not the individual line items).
I also tried creating a System Notes Saved Search, which pulled the details I was looking for, but does not show me the Internal ID of the record (it shows me the "Record", which appears as a string - ex: "Contract #12345"). It also does not show me the ID of the contract line item, so even if I am able to join based on the Contract ID, I don't know which line items were affected.
If I navigate to the contract in NetSuite and look at the Items list, I am able to click the "History" button to see a list of changes - this is the information I am trying to pull. Is there any way to do this through a Saved Search?
Transaction item sublist history, is not yet exposed on the saved search/suitescript.
There might be an enhancement request for this use case.

Suitescript - How do I access the values in "Subsidiaries" sublist on vendor record?

On the vendor record, I need to loop over the Subsidiaries sublist through a scripted search, to get all of the values. I am specifically trying to find vendors that do not belong to a particular subsidiary.
UPDATE
To clear up my question, I was trying to access the Subsidiaries sublist and not the actual primary subsidiary. However NetSuite said that this is currently not possible and is a requested enhancement.
bluejay92, the vendor search has a join to the subsidiary record, see attach screen shot. You can even check "use expressions" to gain access to the NOT function in the criteria.
Workaround:
1 - Create a user event script that runs after the record is created/edited.
2 - Have the script load the record, get the subsidiaries and create a custom record to save the info so you can search it later.
3 - Export all vendors internal ids in 1 column. Run a CSV import of vendors and map internalid csv column to internalid field to trigger the user event script and populate the custom records.
Extra tip: Make sure the script does 'upserts' to the custom record to avoid duplicates. There should be one record per vendor.

NetSuite Site Category Count

Does anyone know how I can retrieve the NUMBER OF ITEMS in a category in netsuite?
I'm hoping for a getAttribute tag of some sort. I need the count of total items in order to create a pagination string url.
The simple method is to create a saved search with the criteria/filters you need.
You can create saved search either programmatically or by using the tools available in netsuite.
The length of the result of saved search will show the total NUMBER OF ITEMS.
NOTE : If you want, you can retrieve the entire details of each product from saved search results.

Getting the greatest value for a field for all records

For our Employee records within NetSuite, we have a custom field called "Employee Number" with an ID of custentity1. I've created a workflow that will automatically create a new employee record and populate various fields but the one I'm having difficulty with is the Employee Number field. All I want to do is to grab the largest employee number there is out of all of the Employee records and add one to it for the new employee record.
The Employee Number field is a free-form text field so I know I'll have to use TO_NUMBER, but anytime I try and reference {custentity1} I keep getting an error saying that field is not found.
UPDATE: I've created a new custom field for our employee records called "Employee No." with an ID of custentity_employeenumber. I've also created a javascript file with the following:
function getMaxEmployeeNumber(){
var empNumber = nlobjSearchColumn('custentity_employeenumber', null, 'max');
return empNumber;
}
But how to do I get this to work with my records?
NetSuite does have an auto-numbering mechanism built in to its native functionality that most of our customers use for this exact purpose. Is there a special reason this functionality is not being leveraged? This functionality is accessible at Setup > Company > Auto-generated Numbers.
I do not work much with workflows, so I do not know if this same functionality is possible there, but here is how I would solve this in SuiteScript:
Create User Event script that is executed on Before Submit Create event for Customer records
Create a Customer search that has a Search Column for custentity1 with a summary type of max
new nlobjSearchColumn('custentity1', null, 'max');
Running this search should give you 1 result, which is the maximum customer number. You can then just add 1 to it.
You could create a similar Saved Search in the UI to see what the result set looks like.
This will only really work if the field is a Number, not Text. I would suggest changing the field to an Integer field if you know that it will always be a number. This may clear out existing data, so first you could export all customers and their number to Excel and then do a CSV import after changing the field.
How are you looking for the last employee in a workflow?
I know this can be done in js:
Search employees - returns max 1000
For number of employees give me the custentity1 of the last one - nlapiLookupfield('employee',employees[employees.length],'custentity1')
Add +1 and save on new record
If you use this search column
nlobjSearchColumn('custentity1', null, 'max');
You can also sort it in decreasing value so that the first result is always the max. Something like
nlobjSearchColumn('custentity1', null, 'max').setSort(true);

Resources