Trying to set the default billing and default ship...
# suitescript
n
Trying to set the default billing and default shipping, but whenever I pass the value as either true or false or T or F, I get an error such as the following: The field defaultshipping contained more than the maximum number ( 1 ) of characters allowed.
b
use Record.selectLine(options) in dynamic mode
before you set values
n
@battk I tried that and still this error: The field defaultshipping contained more than the maximum number ( 1 ) of characters allowed.
Also, this one when I use the value T or F
You have entered an Invalid Field Value T for the following field: defaultshipping
b
dunno what to tell you, your code works reasonably well for me
Copy code
require(["N/record"], function (record) {
  var cacheObj = { companyid: "11" };
  var addressid = "4";
  var defaultbilling = true;
  var defaultshipping = true;
  var addressee = "addressee";
  var city = "sacremento";
  var zip = "95814";
  var state = "CA";
  var street = " 915 I Street";
  var vendorRecord = record.load({
    type: "vendor",
    id: cacheObj.companyid,
    isDynamic: true,
  });
  var numLines = vendorRecord.getLineCount({
    sublistId: "addressbook",
  });
  for (var i = 0; i < numLines; i++) {
    var sublistFieldValue = vendorRecord.getSublistValue({
      sublistId: "addressbook",
      fieldId: "internalid",
      line: i,
    });
    if (sublistFieldValue == addressid) {
      vendorRecord.selectLine({
        sublistId: "addressbook",
        line: i,
      });

      vendorRecord.setCurrentSublistValue({
        sublistId: "addressbook",
        fieldId: "defaultshipping",
        value: defaultshipping,
      });
      vendorRecord.setCurrentSublistValue({
        sublistId: "addressbook",
        fieldId: "defaultbilling",
        value: defaultbilling,
      });

      var addressSubrecord = vendorRecord.getCurrentSublistSubrecord({
        sublistId: "addressbook",
        fieldId: "addressbookaddress",
      });

      // Set all required values here.
      if (addressee) {
        addressSubrecord.setValue({ fieldId: "addressee", value: addressee });
      }
      if (city) {
        addressSubrecord.setValue({ fieldId: "city", value: city });
      }
      if (street) {
        addressSubrecord.setValue({ fieldId: "addr1", value: street });
      }
      if (zip) {
        addressSubrecord.setValue({ fieldId: "zip", value: zip });
      }
      if (state) {
        addressSubrecord.setValue({ fieldId: "state", value: state });
      }

      vendorRecord.commitLine({
        sublistId: "addressbook",
      });
    }
  }
  var recordId = vendorRecord.save({
    enableSourcing: true,
    ignoreMandatoryFields: true,
  });
});
n
Thanks for trying @battk that is just the weirdest thing man. I'll keep working at it but appreciate the help
b
@Nick Were you able to resolve this? Have you tried setting as TRUE ? (boolean true)