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”}]}

Rookie Asked on August 12, 2021 in SuiteScript.
Add Comment
4 Answer(s)

The parameters to Result.getValue shuld match that of search.createColumn. Use the same parametersto get the value as you would to create the column. I also heavily recommend using the single object parameter form of those methods, the order of the keys will start to make a difference here.

Advanced Answered on August 12, 2021.
Add Comment

Thank you for your answer. Forgive my ignorance, but I don’t understand what you are saying. If by “parameters” you mean “url” and “filetype” and “companyname” I do have them the same in the search.createColumn as in the Result.getValue. I have tried using

columns: [“file.url”, “file.filetype”, “companyname”]

and

res.getValue(“file.url”), res.getValue(“file.filetype”), res.getValue(“companyname”)

and get the same result. I do get the information I need with search.lookupFields, but I can’t figure out how to get that for all attached files.

If you would be so kind as to give me some sample code, perhaps it would help.

Rookie Answered on August 13, 2021.
Add Comment

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

Thank you very much.  My apologies for not realizing those were links to code samples.

res.getValue({name: “url”, join: “file”}) is what I needed.

 

Rookie Answered on August 13, 2021.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Limebox   Become a Sponsor   Become a Sponsor