SuiteScript pull sublist without loading main record? - netsuite

I am trying to find out if I can pull a sublist without loading the main record. It seems wasteful when all I need is the sublist and I don't get the sublist back with a saved search. search.lookupFields only gives access to body fields which is so very close. I would like to pull a specific sublist is this possible? Thanks in advance for any help.

Sublists in NetSuite are actually records which are linked through some field(like joins in SQL). Being said that, you can use join property in search.createFilter, search.createColumn, searchResult.getValue etc and pass the common field to it while the name parameter will contain the fieldId of the field that you want to fetch the value of.
Eg to fetch item data from salesorder, you can run the following code
var salesOrderSearchResult = search.create({
type: 'transaction,
filters: search.createFilter({
name: 'internalid',
join: 'item',
operator: 'is',
values: ITEM_INTERNAL_ID
}),
columns: search.createColumn({ name: 'itemid', join: 'item' })
}).run().getRange({ start: 0, end: 100 });
// to fetch results
salesOrderSearchResult.forEach(function (searchResult) {
var itemId = searchResult.getValue({ name: 'itemId' ,join: 'item' });
})

Related

Get country id's from country list on suitescript

I have a script that needs to update a record due to his country.
so I have to make a save search and add a country filter - the problem is that I have the country code or country name but not the country id - the save search need to have the country id
var search_htsCodes = search.create({
type: "customrecordau_test_codes",
filters: [
["custrecord_au_part_number.internalidnumber", "equalto", item],
"AND",
["custrecord_au_country", "anyof", country] // HERE IS THE PROBLEM
],
columns: [
search.createColumn({
name: "internalid",
label: "ID"
})
]
});
Filter expecting numeric value was removed, as non-numeric value 'Estonia' was provided
Any idea how to get this work?
You can try using help id: 63281, 82791
.>Get Country IDs and Country Names on SuiteScript
.>Use SuiteScript to Generate a List/File of All Country and State Names/Abbreviations

SuiteScript How to access the Revenue Recognition Details on the lines of the journal entries

I need to access the details listing on the individual "lines" of Journal Entry Records in SuiteScript. When I look in debugger, the "details" column is not showing. Are the records for this column perhaps searchable in a "query" manner? Or is there some other way to gain access to that data?
thanks in advance for any help.
Via Suitescript to access the details on the individual lines you need to load or create the record, then access the sublist. The sublist id is "line" per the Records Browser. You can use the N/record or N/currentRecord module to get or set values. See example below:
//load record OR create one
var myJournal = record.load({
type: record.Type.JOURNAL_ENTRY,
id: 12345
});
//get line value
var lineAmount = myJournal.getSublistValue({
sublistId: 'line',
fieldId: 'amount',
line: 0
});
//set line value
myJournal.setSublistValue({
sublistId: 'line',
fieldId: 'amount',
line: 0,
value: 100
});

How to lookupfield in lines of Client script API 2.0?

i need to pick a field from item master record. The item type is sometimes service item and sometimes itemgroup. There is some issue in record 'type' and 'id'. Please help.
My Code:
var govFeeFieldInside = search.lookupFields({
type: search.Type.ITEM,
id: item_,
columns:
[
'custitem2'//govFeeInItemMaster
]
});
lookupFields is only for body-level fields. To retrieve sublist data from any record, you will need to either perform a search or load the record.

N/query column definition

I'm trying to get transaction data using the N/query module:
require([ 'N/query'],
function(query) {
var trxQuery = query.create({ type: query.Type.TRANSACTION });
trxQuery.columns = [
trxQuery.createColumn({ fieldId: 'externalid' }),
trxQuery.createColumn({ fieldId: 'account' }),
trxQuery.createColumn({ fieldId: 'fxamount' })
];
var results = trxQuery.run();
})
The help says next thing about setting of fieldId in creating the query column:
Obtain this value (fieldId) from the Records Browser.
1. Go to the appropriate record type.
2. Scroll until you see the Search Columns table.
3. Locate the appropriate value in the Internal ID column.
However, I get the following error:
{"type":"error.SuiteScriptError","name":"SSS_SEARCH_ERROR_OCCURRED","message":"Search error occurred: Field 'account' for record 'transaction' was not found." ...
The same thing happens for fxamount field.
How can I define query column in order to get data on Account and Amount (Foreign Currency) for transactions by using N/query module?
The N/query module allows you to use the same logic as the Analytics Workbooks feature in the UI. For some reason, these workbooks do not always have the same field names that are in the Record Browser. For my two cents, the N/search module is still the way to go. N/query appears to be much slower than N/search.
In the Workbook UI, you can click the info icon next to each field name and see the field ID needed for the query module.
In your example, fxamount for a search is probably foreigntotal in a query.
Also, there doesn't appear to be an account field at the top level transaction or transaction line level. At the Transaction Accounting Line level, there IS an account field.
I'm not sure if its the account field that you're looking for, but this code seems to work.
var trxQuery = query.create({
type: query.Type.TRANSACTION
});
trxQuery.columns = [
trxQuery.createColumn({ fieldId: 'id' }),
trxQuery.createColumn({ fieldId: 'transactionlines.accountingimpact.account' }),
trxQuery.createColumn({ fieldId: 'foreigntotal' })
];
var results = trxQuery.run();

Programmatically create PAYMENT_VENDOR record in NetSuite?

So, this is what I'm doing (hardcoding most values for now, just trying to learn NS):
var vendorBillPayment = record.create({
type: record.Type.VENDOR_PAYMENT,
isDynamic: false,
defaultValues: {
entity: 45
}
})
vendorBillPayment.setValue({
fieldId: 'entityname',
value: "Superior ISP"
})
vendorBillPayment.setValue({
fieldId: 'account',
value: 129
})
vendorBillPayment.setValue({
fieldId: 'currency',
value: 1
})
vendorBillPayment.setValue({
fieldId: 'customform',
value: 45
})
vendorBillPayment.setValue({
fieldId: 'exchangerate',
value: "1.00"
})
var recordId = vendorBillPayment.save({
enableSourcing: false,
ignoreMandatoryFields: true
})
Now, the problem begins in the snippet below, VendorPayment record has a sublist 'apply', which is a list of bills that the payment needs to apply.
vendorBillPayment.setSublistValue({
sublistId: 'apply',
fieldId: 'internalid',
line: 1,
value: "303"
});
The returned error is:
error message:{"type":"error.SuiteScriptError","name":"UNEXPECTED_ERROR","message":null,"stack":["anonymous(N/recordService)","<anonymous>(/SuiteScripts/..)"],"cause":{"type":"internal error","code":"UNEXPECTED_ERROR","details":null,"userEvent":null,"stackTrace":["anonymous(N/recordService)","<anonymous>(/SuiteScripts/..)"],"notifyOff":false},"id":"","notifyOff":false}
That is, not very useful message. I've been going over their documentation, but no win.
EDIT: turns out that the apply sublist is of type list. This means, that one can NOT programmatically add/remove lines from that sublist. Just to edit the existing lines.
Is there another way to programmatically pay the vendor bill, other than creating a VENDOR_PAYMENT record?
Its tough to be certain based on the code you provided but I see two potential issues. First off, the Apply sublist IS listed as scriptable according to NetSuite's documentation. You can see the sublist listed in the Records Browser under Vendor Payment here: https://system.na1.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2016_1/script/record/itemfulfillment.html
You can also see that the 'apply' sublist is specifically called out in the list of Scriptable Sublists here: https://system.na2.netsuite.com/app/help/helpcenter.nl?fid=chapter_N3206326.html
Now on to the code issues. It is not totally clear as I stated before, but based on what you have provided above it would appear that you are attempting to add/edit the 'apply' sublist on a record after it has been saved. You will either need to add the sublist values before saving, or re-load the record before setting the sublist values. The second issue I can see is that you are attempting to set the 'internalid' of the sublist record which you cannot do. I could be wrong but I don't know of any records in NetSuite, custom or otherwise that allow the setting of the 'internalid'. I could provide more clear direction with a larger sample of the script you are trying to write, but as of now that is all that can be gleamed from your example.
If you are doing this all in the same script then you must reload the vendor payment before applying:
var recordId = vendorBillPayment.save({
enableSourcing: false,
ignoreMandatoryFields: true
});
vendorBillPayment = record.load({
type:record.Type.VENDOR_PAYMENT,
id:recordId
});
Also note that if you are receiving the payment against a particular bill you can do this in one step:
var vendorBillPayment = record.transform({
fromType: 'vendorbill',
fromId: 303,
toType:'vendorpayment'
});
// adjust the apply lines as necessary
When creating Vendor Payment, the sublist 'apply' is dependent on the open Vendor Bills of the selected Vendor/Supplier(entity), so it is mandatory that you need to set the Vendor/Supplier(entity) first(which is what you are doing). Having said that, you cannot add/pay a Vendor Bill that doesn't have a status of 'Open' on the Vendor Payment. If you don't see a Vendor Bill in the 'apply' sublist that means that the Vendor Bill is not yet Approved or the amount of it is zero. You want to make sure that the Vendor Bills you want to pay are approved or has a status of 'Open'.

Resources