I need help with `render.mergeEmail()` (<link>) In...
# suitescript
d
I need help with
render.mergeEmail()
(link) In my email template (record type = Transaction) I can specify fields from the customer (such as
customer.subsidiary
). But how do I pass the customer record into
mergeEmail()
? I've tried this, but get error "Wrong parameter type: options.recipient is expected as object."
the help docs use this for recipient:
Copy code
recipient: { type: 'lead', id: 543 }
I've tried types
lead
and
prospect
also. I get the same error for for
lead
, and for
prospect
I get: "You have entered an invalid type argument: prospect"
n
Really shouldn't make any difference but in case the value is not matching the enum, maybe try record.Type.CUSTOMER?
b
the code for render.mergeEmail is:
Copy code
function doMergeEmail(options) {
  var undef = undefined;
  var templateId =
    options !== undef && options !== null && options.templateId !== undef
      ? options.templateId
      : undef;
  utilityFunctions.checkArgs(
    [templateId],
    ["options.templateId"],
    "render.doMergeEmail"
  );
  var mergerObj = invoker(renderApi, "nlapiCreateEmailMerger", [templateId]);
  if (options.entity) {
    checkRecordRefParameter(options.entity, "options.entity");
    invoker(mergerObj, "setEntity", [options.entity.type, options.entity.id]);
  }
  if (options.recipient) {
    checkRecordRefParameter(options.recipient, "options.recipient");
    invoker(mergerObj, "setRecipient", [
      options.recipient.type,
      options.recipient.id,
    ]);
  }
  if (options.customRecord) {
    checkRecordRefParameter(options.customRecord, "options.customRecord");
    invoker(mergerObj, "setCustomRecord", [
      options.customRecord.type,
      options.customRecord.id,
    ]);
  }
  if (options.supportCaseId) {
    if (!util.isNumber(options.supportCaseId)) {
      utilityFunctions.throwSuiteScriptError(
        error.Type.WRONG_PARAMETER_TYPE,
        "options.supportCaseId",
        "number"
      );
    }
    invoker(mergerObj, "setSupportCase", [options.supportCaseId]);
  }
  if (options.transactionId) {
    if (!util.isNumber(options.transactionId)) {
      utilityFunctions.throwSuiteScriptError(
        error.Type.WRONG_PARAMETER_TYPE,
        "options.transactionId",
        "number"
      );
    }
    invoker(mergerObj, "setTransaction", [options.transactionId]);
  }
  var mergeResultObj = invoker(mergerObj, "merge");
  return new EmailMergeResult(mergeResultObj);
}
with the relevant check function being
Copy code
function checkRecordRefParameter(recordRefObj, name) {
  if (
    !recordRefObj ||
    !utilityFunctions.isObject(recordRefObj) ||
    !recordRefObj.id ||
    !util.isNumber(recordRefObj.id) ||
    !recordRefObj.type ||
    !util.isString(recordRefObj.type)
  )
    utilityFunctions.throwSuiteScriptError(
      error.Type.WRONG_PARAMETER_TYPE,
      name,
      "object"
    );
}
d
You're a life saver once again Battk.
!util.isNumber(recordRefObj.id)
the id I was using was a string from
getValue()
(should have paid more attn to the RecordRef definition that explicitly says id is a number) Where'd you get the function? I couldn't find it loaded in the browser
b
suitescript debugger
you have to use the crappy serverside one for N/render
👌 1
103 Views