Search code examples
google-apps-scriptlogic

GAS: Can you use searchFiles on a searchFiles result?


This question might be more of a logical problem than a function problem.

I have two sets of PDFs "bought" and "return". I use this to search for them:

qsBought = "fullText contains 'Bought' and mimeType='" + MimeType.PDF + "'";
qsReturn = "fullText contains 'Return' and mimeType='" + MimeType.PDF + "'";

Every file also have one device type in them. i.e. computer, chromebook, mac or iPad:

I can search for this with:

qsComputer = "fullText contains 'Computer' and mimeType='" + MimeType.PDF + "'";

I then use this to save the search result into a variable.

myFiles = parentFolder.searchFiles(qsXxx)

The result is then pushed to a sheet (that works like a I expect).

  while(myFiles.hasNext()) {
    var file, fileName, s, t;
    file = myFiles.next();
    fileName = file.getName();
    s = fileName.substr(0, fileName.lastIndexOf('.')) || fileName;
    t = s.split(' - ');
  push(output, t, dv, qs);
 }
  • output = colum headers
  • t = the name of the filename split
  • dv = supposed to be the device
  • qs = bought/returned

On every line I want to push out the information about if the devices is returned or bought.

I'm think that I can do a searchFiles(device) on the previous searchFiles(bought/returned) to find all computers bought, then computers returned, chromebooks bought and so on...

I've tried

qsBoughtComputer = "fullText contains 'Bought' and fullText contains 'computer' and mimeType='" + MimeType.PDF + "'";

I don't think searchFiles() support multiple fullText queries in the same search.

I don't fully grasp the logic or how to work with only these functions. If possible, I prefer to work with Googles core functions and repositories (first-party).

Thankful for any help in this!


Solution

  • As @doubleunary said in the comments.

    Why would it not work?

    I should've tried the solution after I made all the necessary changes to the code...

    As I stated in the beginning;

    This question might be more of a logical problem than a function problem.