Print and download file name not same as saved filename
Have a little issue that it getting in the way
When I print a customer quote the file is also saved into the same customer form in the file attachments. This shows the correct customer quote reference ie ref 6990 as part of the file name.
However the same file is also downloaded to the foot of my current window but instead of showing the same quote ref it shows the internal Ninox record ref ie 1524
It is that file that we slide off onto the desktop and then send to the client (but this is causing a few issues as the client then refers to that as a quote number!.
Anyone know how to mod the current scrip to effect that downloaded file ( it is too inconvenient to go to the attachments tab and download the file manually)
current script on print/save button
let myPdf := printAndSaveRecord(this, "118PrintQuote");
let myName := "Quotation.pdf";
importFile(this, myPdf, QteNum + " " + myName);
if 'Draft!' = true then
alert("Draft Quote Only Saved ! Turn Off Draft Flag To Print Final Quote!")
else
if 'Draft!' < true or 'Draft!' = null then
printRecord(this, "118PrintQuote")
end
end
thank you in advance
12 replies
-
Mel Charles
It is not possible to name the downloaded file. You're on a cloud subscription right? Then, I would take a different approach:
Your code could be like:
importFile(this, printAndSaveRecord(this, "118PrintQuote"), QteNum +" Quotation.pdf"); if 'Draft!' then alert("Draft Quote Only Saved ! Turn Off Draft Flag To Print Final Quote!") else let u := shareFile(item(files(this), 0)); openURL(u) end
Normally, the open url should open the PDF and you can print it straight away.
If you want to mail the quote, i would suggest to send it straight from ninox using the attachment (with a button).
Here's an example of a good way to mail with attachments:
Hope this helps you on the road....
Steven
-
HI Steven
Thanks for the quick reply. Yes i am on cloud version. I have already seen you excellent post on mailing within Ninox and have taken some god elements from this for another project i am doing. I already have quite a few options on mailing built in including batched mass mailing the same file out to my customer base etc.
I don't want to send the quote from with in Ninox as the quote file needs to go out with other files and visuals (these are usually too large for me enclose within Ninox and would add extra unnecessary steps)
I'll give your url suggestion a go and see how I get on with that.
As ever ... thank you
Mel
-
Steven
hmmm....... seems to give each file a named string of random letters.
Maybe the way to go is to get it to same to an image field on the front page of the quote (just like the attachment image above) then simply drag it from there. as the file saved in th attachments does have the correct filename and this would save me constantly flicking between tabbed pages..
Unless there is an auto way to down load/copy that file saved in the attachment to desktop using a script?...........Hmmmm
Mel
-
There are two solutions with the JavaScript code:
1st with NaviteJS. This function can be added to the global functions and be used in all the application :
function downloadFile(file : file,destFileName : text) do #{:text // separate the table id, the record number and the file name var file = util.parseNIDFile(file); // If the destination of the file name is not defined, it is set as the current name by default. if (!destFileName) destFileName = file[2]; // create the URL of the file database.shareFile(file[0]+file[1], file[2], (err, url) => { // Creating an html element to apply the standard download var link = document.createElement("a"); link.style.visibility = "hidden"; link.href = url.url; link.download = destFileName; link.click(); // remove html element; link.remove(); }); }# end; "to download from a image/file field"; downloadFile(myImageField, ""); "to download from files of records"; downloadFile(item(files(this.Id), 0), "my file name destination.pdf"); "to download all PDF files of record"; for i in files(this.Id)[like ".pdf"] do downloadFile(i, "") end
2nd one with button from a Ninox html formula
var fileName := extractx(text(myImageField), "^([A-Z]+)([1-9][0-9]*)\/(.*)", "gi", "$3"); var destFileName := "my file name destination.pdf"; html("<script> function download() { database.shareFile('" + string(this.Id) + "', '" + fileName + "', (err, url) => { // Creating an html element to apply the standard download var link = document.createElement('a'); link.style.visibility = 'hidden'; link.href = url.url; link.download = '" + destFileName + "'; link.click(); link.remove(); }); } </script> <button onclick='download()'>My download button</button>")
-
Another update, because there were incompatibilities from one browser to another. This version seems to work well everywhere, although on FireFox it gives you windows with the files instead of downloading them directly.
I think I can improve this soon, it just needs to store the file in the session with the current URI address for it to work. I leave this gibberish for the attention of other developers who would like to help me to make this code work for FireFox .
function downloadFile(fileNinox : file,destFileName : text) do #{:text:callback // separate the table id, the record number and the file name var file = util.parseNIDFile(fileNinox); // If the destination of the file name is not defined, it is set as the current name by default. if (!destFileName) destFileName = file[2]; // create the URL of the file database.downloadURL1(fileNinox) .then((fileURL) => { fetch(fileURL) .then(resp => resp.blob()) .then(blob => { const url = window.URL.createObjectURL(blob); const a = document.createElement('a'); a.style.display = 'none'; a.href = url; a.download = destFileName; document.body.appendChild(a); a.click(); window.URL.revokeObjectURL(url); callback(url.url); }) }); }# end;
-
Hey Guys
Thank you for the input
You will see from my opening thread that I am producing a file into an attachment. When I print to create the file, it does 2 things
1. A file is created and is correctly given a filename that matches the record reference number. Ie Form quotes - Quote Number 1234 and Quote1234.pdf for the file. This file is put directly into attachments tab page
2. Another download file is download at the foot of my browser - which I can easily drag off but this file is labels with Ninox鈥檚 internal record id number ie 895 etc. and bears no meaning to the quote reference.
My issue is that I want to drag/down load this file directly onto desktop. I don鈥檛 want to have to flip tabs to get at the file in the attachments to download.
And the other file needs renaming after every drag to desktop
Jacques - Your script is over my head but I have copied your script for the local formula field
This works but does 2 things,
1. It names the file by a long string name as per my image reply to Steven above
2. and opens a window to show/view that file. Which then also needs downloading and renaming. No sadly i am no further forward.
It also relies on the file being held in an image field - not the attachments field. Essentially all I need to do is have a script to appoint to what I have already that will seek out the attachment in attachment1 and download the file onto my desktop.
Yes - I could email it directly from with Ninox. But I have to add in artwork/design files/various tech specs etc and the files would significantly bloat my Ninox storage - particularly the artwork files which can be several meg alone. where as I have these all store under MS outlook templates ready to go.
Kind regards
Mel
-
Ah spoke to soon.
so copied into main database and all working fine been testing for 1/2 hour of so and worked but now has simply stopped working. (not altered the code)
the small database you did is still functioning. so i am guessing it might be a memory thing due to large number of records?
-
Sorry Ignore my last comment
I had copied the script to my spare play copy and tested
then logged out to get something to eat. then logged back into my live copy wher the code had not been placed yet. Just goes to show how stupid one can be !!!!!
all working fine
Content aside
- Status Answered
-
1
Likes
- 2 yrs agoLast active
- 12Replies
- 982Views
-
4
Following