RE: How do I get ID of all files attached to a record?

I need to get the ID, and other info, for every file attached to a Customer record. I created a Saved Search in the UI which gives me what I need. However if I load and run the search, or create a search, in a User Event Script, in beforeLoad, (or in the Debugger) I get no values. If I use search.lookupFields I get the information from only one file. In the code below, I know that Customer ID 3 has two files attached. In the log you can see it found two entries, but I get no information. And lookupFields gives the same information twice.

search.create({
type: "customer",
filters:[{"name":"internalid","operator":"anyof","values":["3"]}],
columns:[
{"name":"url","join":"file"},
{"name":"filetype","join":"file"},
{"name":"companyname"}
]
}).run().each(function(res) {
log.debug('url: '+res.getValue('url')+', type: '+res.getValue('filetype')+', name: '+res.getValue('companyname'));
var fld = search.lookupFields({
type: search.Type.CUSTOMER, 
id: 3, 
columns: ['file.internalid','file.name','file.filetype']
});
log.debug(fld);
return true;
});

Log:

debug url: null, type: null, name: Anonymous Customer
debug {“file.internalid”:[{“value”:”421″,”text”:”421″}],”file.name”:”8Q Signature Capture on Forms.pdf”,”file.filetype”:[{“value”:”PDF”,”text”:”PDF File”}]}
debug url: null, type: null, name: Anonymous Customer
debug {“file.internalid”:[{“value”:”421″,”text”:”421″}],”file.name”:”8Q Signature Capture on Forms.pdf”,”file.filetype”:[{“value”:”PDF”,”text”:”PDF File”}]}

fredmc Rookie Asked on August 12, 2021 in SuiteScript.
Add Comment
4 Answers

Use the code samples from the documentation I linked. You are using SuiteScript 2.0’s old legacy methods wrong and are failing to make different parameters types match. Use the modern documented versions so you can more easily match parameters.

Advanced Answered on August 13, 2021.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.