how can I find the documents attached to record wi...
# suitescript
s
how can I find the documents attached to record with only knowing the id of the record
m
Create message search Filter : transaction search…id = your id of the record Result : attachement
s
this is for a before submit to confirm that a file was atached
m
please explain to me the purpose of the script what do you want to do
s
we want to make sure that the AP team is attaching the invocie they receive to the vendor bill
so either before submit(uservent ) or saveRecord(clientscript)
m
I believe I have already attempted using client script, but it seems ineffective because the 'mediaItem' or 'media' sublist appears to be inaccessible or unavailable. What I did was create a UE that triggers after record submit, which checks whether the transaction has an attached file. If the search yields no results, the UE sets the vendor bill to 'Pending Approval' and redirects the user to the bill in edit mode. This process will continue as long as there is no attached file. However, as soon as an attached file is found, the bill is automatically set to 'Approved' without redirecting to edit mode."
s
well, how can you check if the transaction has an attachment what would the SQL join table for the attachemnt be ?
m
Create save search on transaction And use in result : file..attachement Export as a script with this : https://chrome.google.com/webstore/detail/netsuite-saved-search-exp/cbpefhoehnbljgflflncaejfmkmofoje
s
yes i wanted to try to do it with sql which is faster
meaning there is join table between file and transaction
s
my search returns; I'm trying to access but it returns undefined Shouldn't the result be a regular js object?
Copy code
let filename;
      vendorbillSearchObj.run().each(function (result) {
        log.debug({
          title: "After result",
          details: result,
        })

        // .run().each has a limit of 4,000 results
        return true;
      });

///result ={
   recordType: "vendorbill",
   id: "19247840",
   values: {
      "file.internalid": [
         {
            value: "325316",
            text: "325316"
         }
      ],
      "file.name": "somehting.pdf"
   }
}
in after submit userevent srcipt how can i set the record to be back into edit mode
m
Use
url.resolveRecord
to generate a URL for the desired record, specifying the record type and ID. Add '&e=T' to the URL to open the record in edit mode. Use
redirect.redirect
with the constructed URL to navigate the user to this record in edit mode.
s
I have researched and switched this to a ClientScript (the file attached seems to be saved to db even before the record is saved we are using the drag and drop app ) "save record" script gives me the option to just not save the record and force the user to fix it no need for redirect. I wish I can speed up the search with SQL which should be faster but this is a good working prototype
I have a field on the record for the cases where there is no file and they can check the box that has no attachment
thank you again @Marc
m
Show me your client script please @Sim Greenbaum
s
why ?
m
to see the logic you put into a script client to make it work.
s
Copy code
var vendorbillSearchObj = search.create({
      type: "vendorbill",
      filters: [
        ["type", "anyof", "VendBill"],
        "AND",
        ["internalidnumber", "equalto", rec.id],
        "AND",
        ["mainline", "is", "T"],
      ],
      columns: [
        search.createColumn({
          name: "internalid",
          join: "file",
          label: "Internal ID",
        }),
        search.createColumn({
          name: "name",
          join: "file",
          label: "Name",
        }),
      ],
    });
    let result = vendorbillSearchObj.run().getRange({
      start: 0,
      end: 100,
    });
    // log.debug({
    //   title: " result",
    //   details: result,
    // });

    let fileid = result[0].getValue({
      name: "internalid",
      join: "file",
    });
    let filename = result[0].getValue({
      name: "name",
      join: "file",
    });
    if (fileid) {}
m
How have switch to client script? you don't have an id until the bill is saved.. How can your saved search return a result if the transaction is in create mode and not saved?
s
you're right! i was testing on vendor bills that exist already edit mode not create back tot he drawing board
so after attaching the file thru drag and drop it does upload the file to a folder and the ID must be attached to the current "record" and is being submitted on save so wish i could validate on client script
m
it won't work using the client script, I haven't found a solution
s
so there is a difference between drap and drop vs the regular ui , the drag and drop saves the file to folder before the record saves but the ui add doesnot ,
m
I think by UI it’s already add because the file is selected from the file cabinet
s
the drag and drop script is sending an fetch reuest and this is the return response i wish i had a way to get that
Copy code
var selectmap={"326320":"admin.txt"};
m
Hmm ok I need to try with drag and drop If a find something with client script