for setting value for 7 fields can we use one func...
# suitescript
a
for setting value for 7 fields can we use one function or we have to use setValue 7 times?
e
I think 7 calls, unless you are using record.submitFields
s
You can always create a helper function to set several values with a single call, like this (using a task record as an example, and SS 2.0):
Copy code
function setValues(nsRecord, values) {
    util.each(values, function(value, fieldId) {
        nsRecord.setValue({ fieldId: fieldId, value: value });
    });
}
	
setValues(taskRecord, {
    title: 'Task Title',
    priority: 'HIGH',
    company: customerId,
    assigned: employeeId,
    startdate: new Date(),
    sendemail: false
});
❤️ 2
a
Thanks
👍 1
j
@scottvonduhn is that something you and your team prefer over having nsRec.setValue per field you're updating. Hadn't really thought about this but it looks a lot cleaner to me. Now I'm wondering why NetSuite just didn't do it that way.
s
I personally prefer doing it this way. I agree that Netsuite should provide this natively, particularly given that they already have a very similar functionality for
record.submitFields
The beauty of programming languages, though, is the ability to extend functionality to your liking, and this is something that makes my code cleaner, so I'll gladly do it where it makes sense (usually when setting three or more fields at a time)