Can you provide me with a sample snippet to create...
# ask-stanley-ai
c
Can you provide me with a sample snippet to create a vendor record using SuiteScript 2.1 and set the address book as well? I also want to set the sample address line by specifying the state, country, zip code, etc.
c
AI generated answer (using internal Slack threads):
Based on the conversations, here is a sample snippet to create a vendor record and set the address book using SuiteScript 2.1:
Copy code
javascript
var record = require('N/record');

var vendor = record.create({
    type: record.Type.VENDOR,
    isDynamic: true
});

vendor.setValue({
    fieldId: 'companyname',
    value: 'Vendor Name'
});

vendor.setValue({
    fieldId: 'subsidiary',
    value: '1'
});

var addressSubrecord = vendor.getSubrecord({
    fieldId: 'addressbook'
});

addressSubrecord.setValue({
    fieldId: 'defaultbilling',
    value: 'T'
});

addressSubrecord.setValue({
    fieldId: 'defaultshipping',
    value: 'T'
});

addressSubrecord.setValue({
    fieldId: 'country',
    value: 'US'
});

addressSubrecord.setValue({
    fieldId: 'addressee',
    value: 'Vendor Name'
});

addressSubrecord.setValue({
    fieldId: 'addr1',
    value: '123 Main St'
});

addressSubrecord.setValue({
    fieldId: 'city',
    value: 'Anytown'
});

addressSubrecord.setValue({
    fieldId: 'state',
    value: 'CA'
});

addressSubrecord.setValue({
    fieldId: 'zip',
    value: '12345'
});

var vendorId = vendor.save({
    enableSourcing: true,
    ignoreMandatoryFields: true
});
This script creates a new vendor record, sets the company name and subsidiary, and then creates an address subrecord. The address subrecord is set as the default billing and shipping address, and the address details are filled in. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.846094847
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.841276228
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.841112077
Please provide your feedback on this answer.