Hello. I have created a PDF file. I want to set th...
# suitescript
n
Hello. I have created a PDF file. I want to set the file ID and file URL in the PDF File. Is there a way I can load the file, and set the desired values and save the file again? I have tried this so far: var file = nsFile.load({id: fileId}); var a = file.getContents(); var encodedString = nsEncode.convert({ string: a, inputEncoding: nsEncode.Encoding.BASE_64, outputEncoding: nsEncode.Encoding.UTF_8 });
b
not sure what you are trying to do
but you won't be able to do it by trying to convert a binary file to utf8
n
So in my file, I want to add the file URL. How can I do that?
Because URL is not generated until the file is generated.
n
No the url and id is defined by the system, the whole point of the url is so you can access it in the NS filecabinet. The ID is generated automatically to prevent collision in the file system rather than creating havoc supplying your own id. Why would you want to mess with either?
b
i believe the key term here is
in my file
n
I don't want to supply my own ID neither the URL. I just want to get these values after the file is saved, and load the file and set those values in the relevant columns in the file.
b
generate a new pdf
n
I don't want to generate new PDF. I want to update that same file. is this possible?
b
not really
you can try finding a pdf parser on npm and see if it works
but generating the pdf again is really the easiest way
n
You could try loading the file, getting the content, altering the content, re-assigning the file content and saving it but I don't think it will work... You are probably better creating the new one and deleting the old afterwards.
Actually, hold that thought, I'm pretty sure if you create a file with the same name it overwrites the file... I feel sure I've done this with plaintext files historically. Not sure about PDF's though.
n
If I generate the PDF again, it will give a new Idea and new URL. So it will not be helpful for me.
@NElliott I can try saving it with the same name.
b
you can overwrite files in netsuite
same everything but the contents change
n
@NElliott and @battk that worked! I created an empty file, get the ID and URL, and then saved it with the actual content. It worked!
Thanks alot!
n
took a little while, glad I recalled that it overwrote the file. Just make sure you don't switch the file folder otherwise you'll end up with duplicate named files in your system although the internal id's will of course differ. 🙂