I created a new custom field in the 'US' address form called 'email', so I can have an email address associated with both the bill to and ship to on a sales order in Netsuite. I am trying to update this field using Suitescript 2.0, but cannot seem to save the changes. Can anyone give any insight?
var salesorder = record.load({
type: record.Type.SALES_ORDER,
isDynamic: true,
id: 6835
});
var shippingAddressSubrecord = salesorder.getSubrecord({fieldId : 'shippingaddress'});
var email = shippingAddressSubrecord.getValue({fieldId : 'custrecord_email_address' }); //returns correctly
shippingAddressSubrecord.setValue({fieldId : 'custrecord_email_address', value: 'test2#gmail.com', ignoreFieldChange: true });
var salesorderid = salesorder.save({enableSourcing: true, ignoreMandatoryFields: true});
This gives the error: "type":"error.SuiteScriptError","name":"OPERATION_IS_NOT_ALLOWED","message":"The subrecord line has already been committed or cancelled. The previous subrecord reference is no longer valid. You must get another reference to the subrecord in order to perform this operation.",
Depends, which script type is this? User Even scripts for example, loading/saving the record would result in an error.
Related
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
I have the id field on a netsuite object. Can I change use the id column as the external id in Netsuite, something like in Salesforce?
You can definitely write a user event script to populate the internal id of any record to it's external ID field. The "externalid" field is exposed via SuiteScript or via csv import
The internal id is a unique auto-generated number which identifies a unique NetSuite record and hence the sequence would change if deletion/inactivation happens For eg.if there are records with internal Ids 1, 2 and 3 in system and 2 gets deleted, then IDs that remain in the system are 1 and 3. User does not have the ability to alter these internal Ids since they are system generated. Hence, they cannot be customized (acc to developer's preference) specially if you want to follow a specific convention.
External Id should contain a value which should be unique across multiple integrated systems.Eg. SFDC (Salesforce). The recommended way is to write an afer submit user event script to populate external ID on all the integrated records and keep these synced in both systems
Here is a sample code in SuiteScript 2.0 which populated external ids for subsidiary, account and department:
var recordType = context.newRecord.type;
log.debug({ title: 'Record Type', details: recordType })
var recordId = context.newRecord.id;
log.debug({ title: 'Record ID', details: recordId })
var rec = record.load({
type: recordType,
id: recordId
});
//Setting External ID on subsidiary
if (recordType == record.Type.SUBSIDIARY)
{
var subExID
=rec.setValue('externalid'(rec.getValue('tranprefix').substring(0, 3)))
log.debug({ title: 'TranPrefix', details: subExID })
}
//Setting External ID on account
if (recordType == record.Type.ACCOUNT)
{
var accExID = rec.setValue('externalid',
rec.getValue('acctnumber'))
log.debug({ title: 'External ID', details: accExID })
}
//Setting External ID on department
if (recordType == record.Type.DEPARTMENT)
{
var deptExID = rec.setValue('externalid', rec.getValue('custrecord_dept_code'))
log.debug({ title: 'External ID', details: deptExID })
}
Please let me know if this is helpful !!!
I want to load a saved search , and set "inactive" field to true.
Problem is I tried to load it , but it failed
I tried this :
var searchRec = record.load({ type: search.Type.SAVED_SEARCH, id: result.id, isDynamic: false });
Also read the help on the N/search module but no answer.
require(['N/search','N/record'])
var search = require('N/search')
var record = require('N/record')
var invoice = record.load({
type: record.Type.INVOICE,
id: 444283
})
log.debug('invoice',invoice)
Hi everyone can someone heelp me figure out how to properly load invoice records, vendor bills/credits ? i try this simple record.load with this enum type and i get errors of:
"name":"INVALID_TRANS_TYP","message":"Transaction type specified is incorrect.",
That error would seem to indicate that the Transaction with Internal ID 444283 is not actually an Invoice. Verify your internal ID and transaction type match up.
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'.