NETSUITE - Error INVALID_KEY_OR_REF when I try to enter the Unit of Measure when creating a sales Order - netsuite

Netsuite gives me an error when I try to enter the Unit of Measure when creating a sales order from SuiteScript with a Client Script.
PART OF CODE:
so.setCurrentSublistValue({
sublistId:'item',
fieldId:'units',
value:'Each', //resultRange[i].getValue({name: 'units'}),
ignoreFieldChange: true,
forceSyncSourcing: true
});
Error message:
I have tried with Name, Plural Name, etc.
I need to know how I should load this field, to possibly bring it with SuiteQL from Units Type records, but I can't get it to accept anything by testing.
can someone please help me?

Related

NetSuite SuiteScript 1.0: Cannot save quote in RESTlet

So I'm trying to create an estimate (quote) within NetSuite using SuiteScript 1.0.
I have been following this example provided from NetSuite's help centre:
Example 1
The following example creates an estimate with two items.
var record = nlapiCreateRecord('estimate');
record.setFieldValue('entity', 79);
record.setFieldValue('memo', 'Estimate Memo' );
record.setLineItemValue('item', 'item', 1, 21);
record.setLineItemValue('item', 'quantity', 1, 10 );
record.setLineItemValue('item', 'price', 1, 1 );
record.setLineItemValue('item', 'item', 2, 21);
record.setLineItemValue('item', 'quantity', 2, 5 );
record.setLineItemValue('item', 'price', 2, 2 );
var id = nlapiSubmitRecord(record, true);
The problem I get however is on that last line, whenever I go to try and save the record:
nlapiSubmitRecord(record, true);
I get the following error:
Module does not exist: ../Client/OFI_ActionButtonsClient.js (SYSTEM_LIBS$debugger.sys#475)
Has anyone else come across this? And know what could be causing the issue? Just for reference I am just running this script through the inbuilt script debugger in NetSuite.
Please note as well, I have tried writing this up using SuiteScript 2.0, and my issue then was that only custom fields were being saved, whereas the primary/ inbuilt fields for the quote in NetSuite had no values added at all.
Thank you
Please provide the entire code. Are you using any library scripts.
Seems you're trying to use a relative path to access a dependency library while running on the debugger
../Client/OFI_ActionButtonsClient.js
Use the full path instead
/SuiteScripts/{your path}/Client/OFI_ActionButtonsClient.js
So I managed to fix the issue. The problem was with me trying to set the customform field. So removing this line in my own code helped fix the issue, and I was able to successfully save the record:
record.setFieldValue('customform', '123' );
Initially I thought it was a problem with the save, but it seems like it was actually happening much earlier on, and only just manifested itself at the point of saving. I'm not entirely sure why that was the case, but for anyone else who might be stuck on this I thought it might be useful to know.
Thanks all.

INVALID_RECORD_TYPE when voiding CHECK in Netsuite using Suitescript 2.0?

I'm trying to void transactions via script. It's working for all the other transactions except for check record and I can't figure out why. I'm getting the INVALID_RECORD_TYPE error.
Here's a sample code I am using.
var id = transaction.void({
type: 'check',
id: 25
});
Thanks.
Please check Setup > Accounting > Accounting Preferences > General: VOID TRANSACTIONS USING REVERSING JOURNALS.
If the preference is not checked, the Void button does not appear in checks and you get the invalid record type error.
Please check the Field Level help of the preference for details. You will need to toggle the preference (using N/config) before calling transaction.void on types that are not covered by your account setting.
You must Reversing Journal
and then this:
var checkId= transaction.void({
type: transaction.Type.CHECK,
id: 25
});

Call NetSuite native calculate shipping button by script?

I am Using User event aftersubmit on Sales order to add/update line item. As soon as line item updated shipping cost should recalculate. I am using real time shipping method and cost.
Now If I change item manually, I need to click ‘calculate’ button under Shipping tab, which calculate and update shipping cost. But when I add/update line item using user event, it became ZERO.
Is there any way to calculate shipping cost by script? Is there any way to run functionality of native ‘calculate’ shipping cost button by script?
For your case i.e User event, we need a dynamic record to do this, so load a dynamic Sales Order record, using id from the Standard record in User Event context:-
var drSalesOrder = record.load({type: record.Type.SALES_ORDER, id: salesOrderId, isDynamic: true});
Then doing the following operations in this order(will calculate and set the shipping cost on the order):-
drSalesOrder.setValue({fieldId: 'shipcarrier', value: 'nonups'});
drSalesOrder.setValue({fieldId: 'shipmethod', value: SHIP_ITEMS.FedEx_Ground}); // your shipmethod id here
drSalesOrder.setValue({fieldId: 'shippingcostoverridden', value: true});
drSalesOrder.save({ignoreMandatoryFields: true, enableSourcing: true});
Not natively. We do the calculation by overriding the page element on pageInit, and adding other operations before running the native NS API call.
I know this question is old but on my case I cant get these answers to work (although its the same what is in SuiteAnswer), and I was stuck for some hours trying to retrigger the computation of shipping cost.
What I did is to call the calculateRates() Netsuite's function on saveRecord function in client script. I am lucky the client does not require this in the server. Although its not the correct way but its more okay than not working :)
const saveRecord = (context) => { Shipping.calculateRates(); return true; }
Hope this helps. Thank you!

Why is vendor bill not saving on update?

I am able to successfully create vendor bills in my script, but for some reason, when I am attempting to save updates/edits to the same vendor bills it will come up with an error message: "Please enter value(s) for: Vendor". Does anyone have any insight to why this may be occurring? I am setting the vendor under the "entity" field like so (in both the update and create calls), and the code is the same for both contexts (in the portion where the fields are set), with a valid internal ID being set for the sellerVendorId value:
vendorBill.setValue('entity', sellerVendorId);
// then saving the vendor bill
vendorBill.save();
It seems you are forgetting to pass through the necessary fields of the setValue object.
vendorBill.setValue({
fieldId: 'entity',
value: sellerVendorId
});

Netsuite bug when creating customerdeposit record

Im trying to create a customer deposit record in Netsuite using suitescript 1.0.
The original code I had in place which had been working perfectly up until the 2016.2 release broke it.
The update broke it, in that it would override the value submitted in the payment field and instantly make it the full amount of the sales order from the sales order ID. Which is not what we need it to do.
Original Code
function createDeposit(request,response)
{
var record = nlapiCreateRecord('customerdeposit');
record.setFieldValue('salesorder','1260');
record.setFieldValue('customer','1170');
record.setFieldValue('payment','100');
record.setFieldValue('account','2');
record.setFieldValue('memo','this is a test');
deposit = nlapiSubmitRecord(record,true,false);
response.write(deposit);
}
After a reply on the Netsuite user group prompted me to use the {recordmode:'dynamic'} attributes I am getting a strange error..
Test Replacement Function which doesnt work
function createDeposit(request,response)
{
var record = nlapiCreateRecord('customerdeposit',{recordmode:'dynamic'});
record.setFieldValue('salesorder','1260');
record.setFieldValue('customer','1170');
record.setFieldValue('payment','100');
record.setFieldValue('account','2');
record.setFieldValue('memo','this is a test');
deposit = nlapiSubmitRecord(record,true,false);
response.write(deposit);
}
The error message Im getting now is
Invalid salesorder reference key 1260 for customer .
The thing I dont get is how it is now considered NULL, when the value is hardcoded into this test script after I apply the {recordmode:'dynamic'} value.
Ive tried a wide variety of things, but as I dont have Netsuite support, its proving to be something I simply cant figure out.
Any hints, suggestions would be greatly appreciated as Ive been on this for several days
When you use dynamic the order you set fields makes a difference. So when you set the sales order prior to setting the customer you are actually getting the error message "Invalid salesorder reference key 1260 for customer blank"
What I do is create the customer deposit like:
var depRec = nlapiCreateRecord('customerdeposit', {entity:soRec.getFieldValue('entity'), salesorder:soId});
also setting the undeposited funds flag seems to be required (but not always for some reason) so since you are supplying an account id also do this:
depRec.setFieldValue('undepfunds', 'F');

Resources