Hi All, Just started using promises in my scripts ...
# suitescript
u
Hi All, Just started using promises in my scripts as they are very convenient and provide a way to implement async. programming in scripts. However, noticed something weird with the file module. When a Suitelet is set to "Available without Login" and we are loading a file in our code it works fine. If we put the file.load part inside a then block of a promise, it returns Permissions error. Has anyone came across this issue before. If so, then it would be very helpful, if you can share how you get around this. Thanks. @battk @humzariaz
b
what does the code and deployment look like
u
This is the deployment. I reverted back the code. But the structure was as below
someFunctionReturningPromise().then(result => {
const fileObj = file.load({id: FILE_ID})
})
This was returning error. However, if I load the file outside the promise, it was working fine.
b
Copy code
/**
 * @NApiVersion 2.1
 * @NScriptType Suitelet
 */
define(["N/file"], function (file) {
  return {
    onRequest: function (context) {
      Promise.resolve()
        .then((result) => {
          const fileObj = file.load({ id: "83" });
        })
        .catch((e) => {
          log.error("e", e);
        });
    },
  };
});
unable to reproduce with that code