Getting data from netsuite using suite script - netsuite

Can someone explain me how to fetch the record from netsuite (eg. if we click on the save button of inventory form, it should capture the record and display) using suite script.
thanks in advance.

You have to write a USER EVENT Script and deploy that script in the record (ex: customer record)
In the afterSubmit function of the script you can use scriptContext to get and display the value.
function afterSubmit(scriptContext) {
log.debug('scriptContext',scriptContext.newRecord); //You can see the record info on debug logs
}
If you want to get the data for some validation purposes you can use beforeSubmit function.

Related

Task field that links to the originating transaction

I have a custom task form that has a field which displays the transaction id (in this case a sales order)for the record the task was created in.
I would like to have this field be a hyperlink to that specific transaction but am lost on how to do this.
Is this possible?
In view mode on the task any records linked under the 'related records' tab are links to the respective record. This is automatic.
If you want on the main section you can add one with a user event script possibly coupled with a client event script.
In the Before Load user event script detect that a transaction is assigned and create a new field of type URL and use the N/url module to derive the url of the transaction.
If the user who needs the link is allowed to change the linked transaction then you could also add a client script that uses a fieldChanged event to update the value of the custom field added in the User Event script.
If you need the client script and want to eliminated duplicate code then you could set the value of the url custom field in the pageInit event of the client script (i.e. both the pageInit and fieldChanged events could use the same url resolution code.
The field must be of type List/Record pointing to a Transaction list, or an HTML type set using an <a href="url"> attribute.
I would advise against hard-coding links in the system though, and try to use the List/Record field type first.
Hope that helps! If not, feel free to comment back and I'll see what other help I can provide. If possible, please provide screenshots.

Display a user friendly message in user event script

I'm trying to do some validations using a user event script but I want to show user some meaningful error instead of the default 'suitescript' error at the end. Is there any way to do this?
User Events are server-side, so there is no UI in which to display a message. You cannot validate date on beforeSubmit and display a message. If you want to validate as the user saves and show them feedback, you need to use the saveRecord entry point on a Client Script.
You can do this via the beforeLoad entry point because it receives a reference to the Form in context, which has an addPageInitMessage entry. Check out the Help docs for this method to see if it will work for your case.
As #erictgrubaugh suggested you cannot use User Event for validation.
If you want to perform validation and stop form submission, you need to use ClientScript with saveRecord and you can perform all of your validations here. If current record does not passes your validation you show user error using N/ui/message with some description and if everything is correct return true.
To stop current record from being saved, return false from saveRecord.
Check this out to see how to use N/ui/message and this for further reading on saveRecord.
You can use "throw" to display error message on before submit.

Netsuite Suitelet - Update view in sublist based on what is on the search form?

I'm trying to display the data in the sublist based on the field input of the search form.
Create a client script create function for fieldChanged event and write operations for and don't deploy this script on any record, you have to use this client script in for using following code.
Use this
form.setScript('CLIENT_SCRIPT_ID);

Add field Netsuite amortization schedule

I would like to add a few fields to the amortization schedule record in Netsuite. However my user event script does not run. I used netsuite's debugger and when I view the record it doesn't even seem to recognize that there is a user event script. The script below works perfectly on other record types like a customer record but I can not get it to work on the amortization schedule record.
function addFieldsBeforeLoad(type, form, request){
form.addField('custpage_test', 'text', 'test');
}
This is clearly mentioned in NetSuite help that -
This record is scriptable in server SuiteScript only.
The user events are not supported.
Hope this will help.

NetSuite Record Creation Event

How can I change a field on a form when it is initially created, but not when it is later edited? I'm currently using a Client script and coding for this with the pageInit function, but I need to allow my users to manually change the field after it is initially created without the script overriding their changes.
Let me know if more details are needed for what I am exactly trying to accomplish.
As I mentioned in a comment above, I figured this out. Using the type parameter of the pageInit function, I can make events fire on page edit or page creation like this:
function pageInit(type){if(type == 'create'){//do stuff}else{//do other stuff}}

Resources