Categories

How to create a customer record in Netsuite using Suitlets

function createRecord(Company_name, MrMs, FirstName, LastName, JobTitle, Phone, fax,  add1, add2, postalCode, City, State,Country,Email,Password ){ 
    var defaultSubsidiary=1; 
    var obj = nlapiCreateRecord('customer',{recordmode: 'dynamic'});
    obj.setFieldValue('isperson', 'F' );
    obj.setFieldValue('firstname', FirstName);
    obj.setFieldValue('lastname', LastName);
    obj.setFieldValue('salutation',MrMs);
//  obj.setFieldValue('') Job Title
    obj.setFieldValue('phone',Phone );
    obj.setFieldValue('email',Email);
    obj.setFieldValue('password',Password );
    obj.setFieldValue('companyname', Company_name);
    obj.setFieldValue('subsidiary', defaultSubsidiary);
    
    obj.selectNewLineItem('addressbook');
    obj.setCurrentLineItemValue('addressbook', 'defaultshipping', 'T');  //This field is not a subrecord field.
    obj.setCurrentLineItemValue('addressbook', 'defaultbilling', 'T');   //This field is not a subrecord field.
    obj.setCurrentLineItemValue('addressbook', 'label', 'First Address Label');  //This field is not a subrecord field.
    obj.setCurrentLineItemValue('addressbook', 'isresidential', 'F');    //This field is not a subrecord field.

     //create address subrecord
    var subrecord = obj.createCurrentLineItemSubrecord('addressbook', 'addressbookaddress');
    
    //set subrecord fields
    subrecord.setFieldValue('country', Country); //Country must be set before setting the other address fields
    subrecord.setFieldValue('attention', MrMs +' '+FirstName +' '+LastName);
    subrecord.setFieldValue('addressee',Company_name );
    subrecord.setFieldValue('addrphone', Phone);
    subrecord.setFieldValue('addr1', add1);
    subrecord.setFieldValue('addr2', add2);
    subrecord.setFieldValue('city', City);
    subrecord.setFieldValue('state', State);
    subrecord.setFieldValue('zip', postalCode);

    //commit subrecord and line item
    subrecord.commit();
    obj.commitLineItem('addressbook');
    
    var id= nlapiSubmitRecord(obj);
    nlapiLogExecution('DEBUG', 'id',id);
    return id;
    
}
adbanner