问题
I can create a customer, lead, contact using RESTlet. But my code is used by someone who created custom fields with required option. When I try to create a customer, I am getting error by custom required fields.
I want to pass the data for custom required fields too. How to know the all custom fields categorized by required and none required using RESTlet?
回答1:
You can use
var record = nlapiCreateRecord(RECORD_TYPE);
var fields = record.getAllFields();
var requiredFields = [];
fields.forEach(function(fieldName){
var field = record.getField(fieldName);
//I am not very sure, its true or T but, below code will work
if(field.mandatory === true || field.mandatory === 'T'){
requiredFields.push(field.getName()) //getLabel() for UI label, as getName returns id;
}
});
//requiredFields array is your need.
回答2:
Actually in this situation I take one of two approaches (or combine them):
The first is to just ignore mandatory fields. You view your code's job is to get information into Netsuite and users will have to be responsible for future updates. You do this by telling Netsuite to ignore mandatory fields when your code saves them:
nlapiSubmitRecord(nlobjRecord, doSourcing, ignoreMandatoryFields); //doSourcing and ignoreMandatoryFields are booleans
or I add a text area parameter to the restlet where the person configuring the restlet has to enter a list of extra fields you want to do something with (e.g. display in a dialog and make required)
来源:https://stackoverflow.com/questions/35178870/how-to-get-all-custom-fields-of-a-particular-record-type-in-netsuite-using-restl