Nbtwist
03/08/2022, 4:48 PMfields = context.fields;
rolemap = {
"Winner": 1,
"Bidder": 2
}
if (context.recordType == "opportunity") {
for (var i = 0; i < fields.length; i++) {
record.attach({
record: {
type: 'opportunity',
id: context["ns_id"]
},
to: {
type: 'customer',
id: fields[i]["contact_id"]
},
attributes: {
role: rolemap[fields[i].label]
}
});
}
Attempting to attach customers to an opportunity record in suitescript, getting some error however
{
"type": "error.SuiteScriptError",
"name": "TypeError",
"message": "execute on com.sun.proxy.$Proxy668.nlapiAttachRecord failed due to: Cannot convert '{versions: [{name: \"netsuiteid\", value: \"7499012\", timestamp: 1646288523546, source: \"API\", sourceVid: [], requestId: \"6dee4522-5322-4906...'(language: JavaScript, type: Object) to Java type 'java.lang.String': Invalid or lossy primitive coercion.",
"stack": [
"Error",
" at Object.attachRecord (suitescript/resources/javascript/record/recordImpl.js:169:11)",
" at <http://Object.post|Object.post> (/SuiteScripts/project.js:19:28)"
],
"cause": {
"message": "execute on com.sun.proxy.$Proxy668.nlapiAttachRecord failed due to: Cannot convert '{versions: [{name: \"netsuiteid\", value: \"7499012\", timestamp: 1646288523546, source: \"API\", sourceVid: [], requestId: \"6dee4522-5322-4906...'(language: JavaScript, type: Object) to Java type 'java.lang.String': Invalid or lossy primitive coercion.",
"stack": "TypeError: execute on com.sun.proxy.$Proxy668.nlapiAttachRecord failed due to: Cannot convert '{versions: [{name: \"netsuiteid\", value: \"7499012\", timestamp: 1646288523546, source: \"API\", sourceVid: [], requestId: \"6dee4522-5322-4906...'(language: JavaScript, type: Object) to Java type 'java.lang.String': Invalid or lossy primitive coercion.\n at Object.attachRecord (suitescript/resources/javascript/record/recordImpl.js:169:11)\n at <http://Object.post|Object.post> (/SuiteScripts/project.js:19:28)"
},
"notifyOff": false,
"userFacing": true
}
CD
03/08/2022, 5:22 PMNbtwist
03/08/2022, 5:23 PMNbtwist
03/08/2022, 5:34 PM{
"type": "error.SuiteScriptError",
"name": "UNEXPECTED_ERROR",
"message": "An unexpected SuiteScript error has occurred",
"stack": [
"Error\n at Object.attachRecord (suitescript/resources/javascript/record/recordImpl.js:169:11)\n at <http://Object.post|Object.post> (/SuiteScripts/project.js:20:28)"
],
"cause": {
"type": "internal error",
"code": "UNEXPECTED_ERROR",
"details": "An unexpected SuiteScript error has occurred",
"userEvent": null,
"stackTrace": [
"Error\n at Object.attachRecord (suitescript/resources/javascript/record/recordImpl.js:169:11)\n at <http://Object.post|Object.post> (/SuiteScripts/project.js:20:28)"
],
"notifyOff": false
},
"id": "",
"notifyOff": false,
"userFacing": true
}
Nbtwist
03/08/2022, 5:35 PMNbtwist
03/08/2022, 5:35 PMrecord.attach({
record: {
type: record.Type.CONTACT,
id: fields[i]["contact_id"]
},
to: {
type: record.Type.OPPORTUNITY,
id: context["ns_id"]
},
attributes: {
role: rolemap[fields[i].label]
}
});