N/query column definition - netsuite

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();

Related

Netsuite: "INVALID_RCRD_INITIALIZE","message":"You have entered an invalid default value for this record initialize operation."

I am new to suitescript and trying to migrate our "units of measure" over to netsuite via suitescript.
I believe the best way to setup an on-demand script execution is 'AfterSubmit' on a user event script, is that accurate? I looked into a scheduled script, but that doesn't really run on demand since it waits for the scheduler.
My 'After Submit' function currently looks like this. I'm trying to create a record under Lists > Accounting > Units of Measure (Unit Type)
const afterSubmit = (scriptContext) => {
var unittype = record.create({ type: 'unitstype', defaultValues: { name: 'Weights' } }); }
When I run the script I get this error:
{"type":"error.SuiteScriptError","name":"INVALID_RCRD_INITIALIZE","message":"You have entered an invalid default value for this record initialize operation."
Is that because I need at least one item in the sublist? Can anyone help point me to the syntax needed to create the sublist item?
I think the use case determines "the best way to setup an on-demand script".
Personally I would make a Scheduled or Map/Reduce script and trigger it to run that on demand by using the "Save & Execute" feature on the script deployment in the UI, or task.create (to trigger it from another script). Scripts can also be executed using the Browser Console.
To resolve the error you received, the defaultValues parameter only works with specific records and fields, can reference Suite Answer Id 45152. Units Type is not a support record. So you need to create the record, set all required values, then save the record.
To create a new Unit of Measure the following should work
//create record
var newRec = record.create({
type: 'unitstype',
isDynamic: //optional
});
//set all desired main line/area values
newRec.setValue({
fieldId: 'name',
value: 'Weights',
ignoreFieldChange: true //Optional, if set to true, the field change and the secondary event is ignored. default is false
});
//set sublist values, if in standard mode
newRec.setSublistValue({
sublistId: 'uom', //Units in the UI
fieldId: '', //will need to set all the required sublist fields
line: 0,
value:
});
//set sublist values, if in dynamic mode
newRec.selectLine({
sublistId: 'item',
line: 3
});
newRec.setCurrentSublistValue({
sublistId: 'uom',
fieldId: '',
value: ,
ignoreFieldChange: true
});
newRec.commitLine({
sublistId: 'uom'
});
//save record for either mode
var newRecId = newRec.save({
enableSourcing: true, //Optional, if set to true, sources dependent field information for empty fields. default is false
ignoreMandatoryFields: true //Optional, if set to true, all standard and custom fields that were made mandatory through customization are ignored. default is false
});
For more information about dynamic and standard record, can reference Suite Answer Id 73792

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 can I set the Sales Team employee on an estimate in NetSuite with a script?

I'm working in NetSuite and I have a custom field on an estimate for the outside sales rep. When the record is submitted, I want the employee field under the Sales Team subtab to be set to the same value as the custom outside sales rep field. However, when I try to do this with a user event script, nothing happens. I am using the after submit function. Any suggestions? Here is what my code looks like:
function afterSubmit(scriptContext){
var record = scriptContext.newRecord;
var outsideSalesRep = record.getValue({
fieldId: 'custbody_bs_salesrep_outside'
});
record.setSublistValue({
sublistId: 'salesteam',
fieldId: 'employee',
line: 0,
value: outsideSalesRep
});
}
You have to do this in beforesubmit, not after (unless you're explicitly reloading the record and saving it again in your script). The record has already been written to the database in aftersubmit & the object returned by scriptContext.newRecord is essentialy readonly, that's why it's discarding the changes.

SuiteScript. How to retrieve primary contacts from customer record. if the type is company

When I am choosing the customer (type: Individual) First and Last name retrieves into the same fields see 1st screenshot, but it doesn't work with type: company. So I created a primary contact in Customer record and want the code retrieve primary contact.see 2nd screenshot. How do I can retrieve first and last name if I choose customer with type: company. like in the 1st screenshot.
if (scriptContext.fieldId === 'custrecord_cc_customer'){
var value = objRecord.getValue({
fieldId: 'custrecord_cc_customer'
});
var fieldLookUp = search.lookupFields({
type: search.Type.CUSTOMER,
id: value, // Customer ID from customer field
columns: ['firstname', 'lastname']
});
objRecord.setValue({
fieldId: 'custrecord_cc_firstname',
value: fieldLookUp.firstname,
});
objRecord.setValue({
fieldId: 'custrecord_cc_lastname',
value: fieldLookUp.lastname,
});
}
return true;
Since, contacts is sublist on customer record so you need to use getSublistText or getCurrentSublistText if you are working on record object, where sublistId is contactroles and fieldId is contact.
If you have a search object, you have to add search column with join where column name is entityid and join is contact.
So, your search.lookupfields should have a contact.entityid in a search column.

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