Anyone remembers how to add a Ship To Address to a...
# suitescript
a
Anyone remembers how to add a Ship To Address to a Sales Order without adding that address to the customer address book? Ship to Select (
shipaddresslist
) = Custom.
a
@battk Yep I wish that work...
b
should work reasonably well in server script
a
It does not want to work for me...
b
probably want to simplify something that can run in the debugger
Copy code
require(["N/record"], function (record) {
  var rec = record.create({
    type: record.Type.SALES_ORDER,
    isDynamic: true,
  });
  rec.setValue({
    fieldId: "entity",
    value: "9",
  });

  log.debug("rec address before", rec.getValue({ fieldId: "shipaddress" }));
  log.debug(
    "rec shipaddresslist before",
    rec.getText({ fieldId: "shipaddresslist" })
  );

  rec.setValue({
    fieldId: "memo",
    value: "102A",
  });
  var subrec = rec.getSubrecord({
    fieldId: "shippingaddress",
  });
  subrec.setValue({
    fieldId: "country",
    value: "US",
  });
  subrec.setValue({
    fieldId: "city",
    value: "New York",
  });
  subrec.setValue({
    fieldId: "state",
    value: "New York",
  });
  subrec.setValue({
    fieldId: "zip",
    value: "10018",
  });
  subrec.setValue({
    fieldId: "addr1",
    value: "8 W 40th St.",
  });
  rec.selectNewLine({
    sublistId: "item",
  });
  rec.setCurrentSublistValue({
    sublistId: "item",
    fieldId: "item",
    value: "9",
  });
  rec.setCurrentSublistValue({
    sublistId: "item",
    fieldId: "quantity",
    value: "11",
  });
  rec.commitLine({
    sublistId: "item",
  });

  log.debug("rec address after ", rec.getValue({ fieldId: "shipaddress" }));
  log.debug(
    "rec shipaddresslist after",
    rec.getText({ fieldId: "shipaddresslist" })
  );

  var recId = rec.save();

  var reloaded = record.load({ type: "salesorder", id: recId });
  log.debug("reloaded address", reloaded.getValue({ fieldId: "shipaddress" }));
  log.debug(
    "reloaded shipaddresslist",
    reloaded.getText({ fieldId: "shipaddresslist" })
  );
});
message has been deleted
a
@battk It does not work in beforeSubmit, only afterSubmit.
b
are the subrecords fields correct and the shipaddress field wrong
a
beforeSubmit it does not save the custom changes at all... after submit it works correctly...
b
thats unfortunate
my minor experimentation suggests that saving a record in standard mode mostly works while dynamic mode does not
the mostly part being the shipaddress text isnt updated
a
yep, crazy stuff... but it is what it is, I remember seen this before...
b
try removing the subRecord and then set it (and potentially overwrite the shipaddress field)