michoel
10/26/2020, 6:47 AMcontext.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
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:
{
"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
}
battk
10/26/2020, 6:48 AMbattk
10/26/2020, 6:51 AMbattk
10/26/2020, 6:57 AMmichoel
10/26/2020, 7:04 AMmichoel
10/26/2020, 7:05 AMconst 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>`);
michoel
10/27/2020, 1:08 AMmichoel
10/27/2020, 1:08 AMError!: {"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}
michoel
10/27/2020, 1:10 AMconst 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 likebattk
10/27/2020, 1:11 AMbattk
10/27/2020, 1:12 AMmichoel
10/27/2020, 1:13 AMsublistFields.forEach(field => journalRecord.setSublistValue(field))
works perfectlymichoel
10/27/2020, 1:13 AMsublistFields.forEach((field, index, array) => journalRecord.setSublistValue(field, index, array))
michoel
10/27/2020, 1:14 AM