How do I create a Lead in SuiteScript 2.0? The fo...
# suitescript
m
How do I create a Lead in SuiteScript 2.0? The following does not work:
rec = record.create({
                    
type: record.Type.LEAD,
                    
isDynamic: true,
                    
defaultValues: {
                        
companyname: context.CompanyName,
                        
subsidiary: defaultSub,
                        
isperson: false,
                        
email: context.EmailAddress,
                        
phone: context.PhoneNumber,
                        
comments: context.Comments
                    
}
                
});
question answered 1
c
Do those
context.
values actually exist? Do you
save()
the record?
s
you cannot use defaultValues for just anything, everything in there is doing nothing most likely since I dont believe leads are supported for defaultValues https://system.netsuite.com/app/help/helpcenter.nl?fid=section_4267255811.html#bridgehead_4423371543
r
If I recall correctly, LEAD is just a status of the Customer record. There is no LEAD record type
m
Thanks everyone for your help. The issue was that Leads do not accept default values.
s
Default values do not work most of the time. If you want a single function that sets multiple fields in a key-value style way, like your original code, you could define a function that takes a record and an object, and sets all of the values like this:
m
Scott - I like that function
s
Could be made even more compact if using SS 2.1, but yes it is a handy little function, and we do use it quite a lot for things like creating task records when we have to set many fields at once. The util.each could be replaced with your preferred iterator (lodash, etc.)
m
👍
m
I usually do something like this in SS2.1
Copy code
for (const [fieldId, value] of Object.entries(bodyFields)) {
  recordObj.setValue({ fieldId, value });
}
s
just use NFT