Hi I am posting a part of my M/R script and an err...
# suitescript
n
Hi I am posting a part of my M/R script and an error below and have a question if someone could answer for me: Code: function reduce(reduceContext) { var arr_preApptSurvey = []; var apptmtId = reduceContext.key; log.debug('apptmtId', apptmtId); var customer_id = search.lookupFields({ type: 'calendarevent', id: apptmtId, columns: ['company'] }); log.debug('customer_id', customer_id); var preApptSurveysSearch = search.create({ // This is Line 50, the one that throws error type: 'customrecord848', filters: ['custrecord_customer', 'is', customer_id], columns: [ search.createColumn({ name: 'id', sort: search.Sort.ASC, label: 'ID' }) ] }); } Error: {"type":"error.SuiteScriptError","name":"TypeError","message":"Cannot find function _marshal in object [object Object].","stack":["createError(N/error)"],"cause":{"message":"Cannot find function _marshal in object [object Object].","fileName":"/SuiteScripts/MR - Link Pre Appt Survey To Appt.js","lineNumber":50,"name":"TypeError","stack":"\tat /SuiteScripts/MR - Link Pre Appt Survey To Appt.js:50 (reduce)\n\tat INVOCATION_WRAPPER$sys:72\n\tat INVOCATION_WRAPPER$sys:25\n\tat INVOCATION_WRAPPER$sys:107\n\tat INVOCATION_WRAPPER$sys:4\n","rhinoException":"org.mozilla.javascript.EcmaError: TypeError: Cannot find function _marshal in object [object Object]. (/SuiteScripts/MR - Link Pre Appt Survey To Appt.js#50)"},"notifyOff":false,"userFacing":true} Question: I figured that it is the search object that is throwing error. And I can't use search.lookupFields & search.create altogether and managed to duck this by loading the record and getting the value. But I think I am missing something basic here and there must be a better way to do this. If someone knows what I missed, feel free to reply. Thanks in advance!
j
search.lookupFields
returns an object, even if you only ask for one column in other words, the value of your
customer_id
variable is something like
{ company: '123456' }
, as a result, the filter expression you pass to search.create is invalid
n
Thanks. That makes sense. I'm going to try this.
Sorry, but this still don't work. The idea here is that the customer_id was returned correctly and was okay. But the search expression still throws error. And as soon as I stop using search.lookupfields, the search expresion becaomes valid. The problem being the lookup individually is working fine. And the Search.create individually is working excellently. But both just won't work with the same search object. I still don't have a solution here. I am at a loss. Thi should be quite simple when I figure this out. But for now, this is a headache. @karlenigma You have any idea how to overcome this?
k
@Nik Your code for the lookup should be
Copy code
var customer_id = search.lookupFields({
        type: 'calendarevent',
        id: apptmtId,
        columns: ['company']
    }).company;
This would pull the company out.