hi guys! I am working on creating contact using su...
# suitescript
p
hi guys! I am working on creating contact using suitescript but i give error like "`"type": "error.SuiteScriptError",`
"name": "UNEXPECTED_ERROR",
`"message": "TypeError: Cannot call method \"getParameter\" of undefined (Contact Company from URL.js$1108550#5)",`", I have used srcript as
var contact = record.create({
type: record.Type.CONTACT, isDynamic: true, }); contact.setValue({ fieldId: 'subsidiary', value: '2' }); contact.setValue({ fieldId: 'firstname', value: requestBody.firstname }); contact.setValue({ fieldId: 'email', value: requestBody.email }); contact.setValue({ fieldId: 'isperson', value: 'T' }); contact.setValue({ fieldId: 'lastname', value: requestBody.lastname }); contact.setValue({ fieldId: 'custentity_pg_cus_short_name', value: requestBody.firstname }); contact.setValue({ fieldId :'custentity_cseg_cust_cat_segmt', value: '1' }); contact.setValue({ fieldId :'custentity_cseg2', value: '6' }); contact.setValue({ fieldId: 'entityid', value: requestBody.firstname + " " + requestBody.lastname }); contact.setValue({ fieldId: 'companyid', value:'2085' }); contact.setValue({ fieldId: 'parentcompany', value:'2085' }); contact.save({ ignoreMandatoryFields: true }); return contact;
b
Probably want to test your code in isolation from the rest of the code
your problem looks related to a line which calls getParameter
I would also be very weary of returning your contact after it has been saved
you risk it being saved again, which will fail
s
also, I don't think 'isperson' is a field for contacts?
'just sayin. Pains me to look at all that boilerplate function calls for things natively supported in the programming language (e.g. object instantiation and property assignment)
🙌 1
m
@stalbert I've started using a pattern like so which makes it much more tolerable without extra dependencies
Copy code
const contactFields = {
  subsidiary: 2,
  firstname: requestBody.firstname,
  email: requestBody.email,
  isperson: true,
  // etc..
}

for (const [fieldId, value] of Object.entries(contactFields)) {
  contact.setValue({ fieldId, value });
}
🙌 2
s
that's shorter code indeed, but obscures what's going on. What we're doing here is assigning values to fields on a record - aka an equals sign - something built in to the javascript language and understood by everyone.