Search payment records information in Netsuite using Suitelet - netsuite

Need to get payment data from Transaction >> Payable >> Pay single vendor form and create a data file. This has been done with an eventscript (add button), a clientscript and a Suitelet by searching currentRecord data from client script to Suitelet and generated a file. However, searching Transaction record type could not get payer payment department and cost center data as I know. So any advice and recommendation from Netsuite experts on how can get these payer data from Netsuite with the existing Transaction information on the Bill Payment form, like payment check number, entity id, transaction number, etc ?

When using the N/search module the following 3 tools are invaluable for retrieving data from netsuite transactions.
Netsuite records browser (shows all of the fields, available search filters, and joins ect.)
https://www.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2020_1/script/record/vendorpayment.html
Another great tool is an extension called Netsuite Field Explorer developed by Michoel Chaikin
you can also turn on field ids in your account by navigating to Home->Set preferences->General tab->Set defaults->Show internal ids
(This will show the field id when you click on the field "What is this?" link directly on the record)
between the three you should be able to get everything you need to run a search and retrieve the data you are looking for.
Depending on your needs you can either search.create (return multiple records) or search.lookupfield(return a single record)

Related

How to fetch the Finance Charge Preferences values using SuiteScript in NetSuite?

We need to perform calculations in SuiteScript using the values in Setup/Accounting/Finance Charge Preferences. Which record is this stored on? Specifically, we're looking for these finance charge fields:
Annual Rate
Minimum Finance Charge
Grace Period
We've tried to create saved searches in all of the obvious records but have not been able to find these fields.
Not documented but N/runtime can be used to get this info (at least in the console)
require(['N/runtime'], runtime=>{
const user = runtime.getCurrentUser();
console.log(user.getPreference({
name:'FC_GRACEPERIOD'
}));
});
You can get the field ids by clicking the field help on the Finance Charge Preferences page.
If that doesn't work to get the fields you can see if the fields are available but not documented by creating a server side script (I'd use a suitelet) to get the accounting preferences object and dump the field names.
If the config module was available client side this would be the console version:
require(['N/config'], config=>{
const conf = config.load({type:'accountingpreferences'});
conf.getFields().forEach(f=>console.log(f));
});

How to get a sales order ID and set it in a Custom Record in netsuite?

I am very new to netsuite. I want to redirect a user from sales order to a custom record I created on button click, I want to get sales order ID and set it in the custom form where the user is being redirected by clicking a button the way fulfillment works in netsuite. I am using client script to redirect user when the button is clicked. Is there a way to pass the sale order id to the next form/Record?
Like this
https://i.stack.imgur.com/QghDv.png
I tried to use the saved search feature but I couldn't fully understand it. If indeed it can be done through saved search, it would be a great help if someone could guide me.
In your Client Script you can use the N/currentRecord module to retrieve the ID of the record in context. It will allow you to retrieve a reference to the CurrentRecord object, which will have an id property.
See the Help page for N/currentRecord for details.

How to modify a Customer Refund in an After Submit User Event

After a new Customer Refund record is saved (After Submit user event) I need to communicate with an external web service and then update 2 fields in the record. When this code is executed to load the Customer Refund
var o = nlapiLoadRecord("customerrefund", 1906);
This error message is returned:
INVALID_TRANS_TYP
Transaction type specified is incorrect.
I found a list of supported records in the "Chapter 60 SuiteScript Supported Records" of SuiteScript Developer & Reference Guide which says the Customer Refund is only available in a server side script.
How should I go about updating the Customer Refund record?
Without seeing more code, it looks ok. I would double check that the internalId of 1906 is correct.
Also, if you're just submitting two fields, I would use nlapiSubmitField(), this will take less governance points and be quicker for NetSuite rather than nlapiLoadRecord / nlapiSubmitRecord.
Your code looks correct, if you are updating the current record I would recommend using below code to avoid incorrect internalid:
var o = nlapiLoadRecord("customerrefund", nlapiGetRecordId());
Also, I would recommend that if you need to update the fields, consider using before submit user event script on customer refund and you can update the fields using nlapiSetFieldValue(FIELD_ID, FIELD_VALUE). No need to submit the record in case of before submit.
If your script is deployed in the customer refund record, you can also do nlapiGetRecordType().

Workaround to search Netsuite Note record by Customer id

I'm trying to get an app I'm working on to display all associated user notes for a given Customer record (as it appears on the UI Customer record page in Netsuite proper).
To that end, I've set up a Netsuite RESTlet to return a list of internal ids for associated Note records given a Customer internal id.
I've set up a simple search in the RESTlet script:
function get_notes(params) {
log("GET params", JSON.stringify(params));
var filters = [
new nlobjSearchFilter('internalid', 'customer', 'is', params.id)
];
var columns = [
new nlobjSearchColumn('internalid'),
new nlobjSearchColumn('note'),
];
var search = nlapiCreateSearch('note', filters, columns);
var notes = search.runSearch().getResults(0, 3);
return notes;
}
function log(msg, details) {
nlapiLogExecution('DEBUG', msg, details);
}
The script works as expected, but the problem is that this search ONLY returns Notes for which the author field (which is a user internal id) matches the internal id of the user performing the search. Meaning - you can only search for Notes for which you are the author.
I have been informed that this is a 'feature' of Netsuite for some unfathomable security reason.
I need to be able to get a list of all the associated Note ids, not just those for which the user making the request is the author.
Any ideas on a workaround to get at all the associated Notes? A different way to structure the search? Some kind of secret way to define your own custom Search Joins?
I can't even find documentation on this behavior (blocking Note searches from non-authors). Perhaps someone knows how to override it at the admin level?
I'm not quite ready to admit that this is impossible yet.
NB: User Note is a Note-type record associated with the Customer record, not a field on Customer record, so I can't access it directly from Customer. There is also not a Search Filter or Search Join for Note or User Note.
Using RESTlets you cannot get the notes of other users unless you invoke the RESTlet using credentials/tokens of roles like Administrator/Full Access. RESTlets always runs in the context of current user.
One alternative to do that, if you really got to achieve this any how:
1) Create a user event script on customer which creates a custom record that simulates the functionality of system notes.
2) Make sure that the RESTlet user roles have full level of access on the custom record and make customer as parent of your custom record.
3) In your RESTlet return the custom records.
Basically RESTLETS always run as the user who invokes them.
If you can use a Suitelet for this you can set that up to run as Administrator and can return any Notes you can craft a search for.
Are you actually needing a Restlet ? i.e. Are you calling this from an external application or are you trying to add functionality in the NS GUI? If the latter then you can easily use a Suitelet.

nlapiResolveURL, identifiers?

I'm having trouble finding the identifiers for the nlapiResolveURL command. According to the dev guide, nlapiResolveURL(type, identifier, id, displayMode) and identifier is identifier {string} [required] - The primary id for this resource (recordType for RECORD, scriptId for SUITELET)
for bill payments the recordType is vendorpayment not VendPymt I have been searching in the dev guide for the list of recordTypes but I can seem to find the list of recordTypes to use for nlapiResolveURL
Check the Records Browser for a list of all Records. The page for each Record Type will display its Internal ID, which is always in all lowercase letters (e.g. "salesorder", "invoice", "journalentry").
In addition to that, when you are running SuiteScript in the context of a record (e.g. User Event or Client Script), you can use nlapiGetRecordType() to get the type's internal ID.
Edit: Just found the page title SuiteScript Supported Records in the NetSuite Help. This has a list of all record types supported by SuiteScript along with their internal IDs. There is an accompanying Web Services Supported Records if you're using the SOAP API as well.
Check SuiteScript Supported Records to check the internal id's of records that is to be used in identifier.
Make a bookmark on your browser and paste this as the link
javascript:if(nsRecordTypes==null){nsRecordTypes=nsServerCall(nsJSONProxyURL,"getRecordTypes");};console.log("nsRecordTypes");console.log(nsRecordTypes)
Then go to NetSuite and open the console (F12 in Chrome > console), and press the bookmark button.
This will show all record types in NetSuite.

Resources