Anyone faced issues with `context.response.sendRed...
# suitescript
m
Anyone faced issues with
context.response.sendRedirect
in SS2.1? I need to create a record in a Suitelet and then redirect to it. The code I'm trying is
Copy code
var purchaseOrderId = createPurchaseOrder(values);

context.response.sendRedirect({
  type: http.RedirectType.RECORD,
  identifier: record.Type.PURCHASE_ORDER,
  id: purchaseOrderId,
});
In SS2.0 it works as expected. In SS2.1 I get this error:
Copy code
{
  "type": "error.SuiteScriptError",
  "name": "TypeError",
  "message": "execute on com.sun.proxy.$Proxy661.sendRedirect failed due to: Multiple applicable overloads found for method name sendRedirect (candidates: [Method[public abstract void com.netledger.app.common.scripting.common.nlobjResponseInterface.sendRedirect(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.Object) throws java.lang.Exception], Method[public abstract void com.netledger.app.common.scripting.common.nlobjResponseInterface.sendRedirect(java.lang.String,java.lang.String,java.lang.String,boolean,java.lang.Object) throws java.lang.Exception]], arguments: [RECORD (String), purchaseorder (String), 19773574 (Integer), false (Boolean), DynamicObject<null>@22d85ccb (DynamicObjectBasic)])",
  "stack": [
    "Error",
    " at Object.onRequest (/SuiteScripts/Fronde/suitelet/cars_pf_create_po_sl.js:19:22)"
  ],
  "cause": {
    "message": "execute on com.sun.proxy.$Proxy661.sendRedirect failed due to: Multiple applicable overloads found for method name sendRedirect (candidates: [Method[public abstract void com.netledger.app.common.scripting.common.nlobjResponseInterface.sendRedirect(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.Object) throws java.lang.Exception], Method[public abstract void com.netledger.app.common.scripting.common.nlobjResponseInterface.sendRedirect(java.lang.String,java.lang.String,java.lang.String,boolean,java.lang.Object) throws java.lang.Exception]], arguments: [RECORD (String), purchaseorder (String), 19773574 (Integer), false (Boolean), DynamicObject<null>@22d85ccb (DynamicObjectBasic)])",
    "stack": "TypeError: execute on com.sun.proxy.$Proxy661.sendRedirect failed due to: Multiple applicable overloads found for method name sendRedirect (candidates: [Method[public abstract void com.netledger.app.common.scripting.common.nlobjResponseInterface.sendRedirect(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.Object) throws java.lang.Exception], Method[public abstract void com.netledger.app.common.scripting.common.nlobjResponseInterface.sendRedirect(java.lang.String,java.lang.String,java.lang.String,boolean,java.lang.Object) throws java.lang.Exception]], arguments: [RECORD (String), purchaseorder (String), 19773574 (Integer), false (Boolean), DynamicObject<null>@22d85ccb (DynamicObjectBasic)])\n at Object.onRequest (/SuiteScripts/Fronde/suitelet/cars_pf_create_po_sl.js:19:22)"
  },
  "notifyOff": false,
  "userFacing": true
}
b
use 2.0
alternatively wait until your account is on 2020.2
notably this error shows the java backend
m
Thanks @battk. I've tested on a 2020.2 account and indeed it is fixed there
Meanwhile I've gone with a manual redirect so I can get on with development until our sandbox gets upgraded
Copy code
const redirectUrl = url.resolveRecord({
  recordType: record.Type.PURCHASE_ORDER,
  recordId: purchaseOrderId,
});

context.response.write(`
  <head>
      <meta http-equiv="refresh" content="1;URL=${redirectUrl}" />
  </head>
  <body>
      <p>If you are not redirected <a href="${redirectUrl}">click here</a>.</p>
  </body>`);
@battk I came across another error that exposes the java
Copy code
Error!: {"type":"error.SuiteScriptError","name":"TypeError","message":"execute on com.sun.proxy.$Proxy800.setSublistValue failed due to: Cannot convert 'line'(language: JavaScript, type: string) to Java type 'java.lang.Integer': Invalid or lossy primitive coercion.","stack":["Error","    at /SuiteScripts/cars_move_partial_credit.js:119:50","    at Array.forEach (native)","    at createReversingJournal (/SuiteScripts/cars_move_partial_credit.js:119:19)","    at moveCreditNote (/SuiteScripts/cars_move_partial_credit.js:72:34)","    at Object.onRequest (/SuiteScripts/cars_move_partial_credit.js:23:22)"],"cause":{"message":"execute on com.sun.proxy.$Proxy800.setSublistValue failed due to: Cannot convert 'line'(language: JavaScript, type: string) to Java type 'java.lang.Integer': Invalid or lossy primitive coercion.","stack":"TypeError: execute on com.sun.proxy.$Proxy800.setSublistValue failed due to: Cannot convert 'line'(language: JavaScript, type: string) to Java type 'java.lang.Integer': Invalid or lossy primitive coercion.\n    at /SuiteScripts/cars_move_partial_credit.js:119:50\n    at Array.forEach (native)\n    at createReversingJournal (/SuiteScripts/cars_move_partial_credit.js:119:19)\n    at moveCreditNote (/SuiteScripts/cars_move_partial_credit.js:72:34)\n    at Object.onRequest (/SuiteScripts/cars_move_partial_credit.js:23:22)"},"notifyOff":false,"userFacing":true}
Was trying to be smart and do
Copy code
const sublistFields = [
  { line: 0, sublistId, fieldId: "account", value: debitAccount },
  { line: 0, sublistId, fieldId: "debit", value: unapplied },
  { line: 0, sublistId, fieldId: "entity", value: entity },
  { line: 0, sublistId, fieldId: "memo", value: memo },
  { line: 1, sublistId, fieldId: "account", value: creditAccount },
  { line: 1, sublistId, fieldId: "credit", value: unapplied },
  { line: 1, sublistId, fieldId: "memo", value: memo },
  { line: 1, sublistId, fieldId: "entity", value: entity },
];

sublistFields.forEach(journalRecord.setSublistValue);
but I realised that adding the index and array to each call which NetSuite doesn't like
b
a lot of the suitescript methods require that the value of this is correct
either use bind, or the second parameter of forEach
m
sublistFields.forEach(field => journalRecord.setSublistValue(field))
works perfectly
i thnk the issue was it was doing
sublistFields.forEach((field, index, array) => journalRecord.setSublistValue(field, index, array))
and NetSuite has undocumented overloads for passing parameters directly and not as an object