Is the “Upload File” module for images only?

General Add comments
by:

A few years ago Service-Now decided to change the file upload functionality. If I am correct that was in the Berlin release. Before that version it was possible to upload any sort of file and customers were using this feature as some sort of repository.

Currently only images upload is supported in the system. If you look at the wiki page on the Upload File module ( https://wiki.servicenow.com/index.php?title=Legacy:Uploading_a_File ) you’ll see that it has been marked “Legacy” .The disclaimer says that this functionality has been replaced by “Storing Images in the Database”. As the name already indicates: this unfortunately only works for images and not for other types of files.

If you test this in an instance you may get the idea that you can still upload a “non image” file, like the test.rtf file in my example below:

However if you want to access it (click on the test.rtf or when using a direct link to the file) you’ll get an error message telling you that the resource is not available:

If you upload an image file, this still works as expected and clicking on it will show you the image file ( if it’s a .jpg or .png). In fact, this is the so-called “Storing Images in the Database” functionality.

So could we conclude that it’s only possible to store image files in the system?
Well, for this “File upload” feature we could say that, however there is an alternative way to get this “repository” functionality back for other file types as well.
There is an easy way to achieve this, by following the next 5 steps!

  1. First create a new table specifically for holding these uploaded files. I called my table “u_file” but you can give it any name you want.
  2. If High Security is installed, and it is set to “Default deny”, add an empty ACL to give the correct access to the new table.
  3. Now you can attach the files to the records on the new “u_file” table. You can add multiple attachments to one record or create a specific record for each separate file in this table. Please make sure that the filenames of the attached files are unique (just as you would have with the SCS directory).
  4. The next step is to create a new UI page. Give it the name “get_file” and use the below code in the HTML field:
    [cc lang=’html’]



    var jvar_attachment_url = “test”;
    var fileName = RP.getParameterValue(‘name’);
    var gr = new GlideRecord(‘sys_attachment’);
    gr.addQuery(‘file_name’, fileName);
    gr.query();
    if (gr.next()) {
    var jvar_attachment_url = ‘sys_attachment.do?sys_id=’ + gr.sys_id;
    }
    jvar_attachment_url;



    [/cc]
  5. If you did it correctly, and you did of course 😉 , you are now able to get the specific file (filename.doc here) by using this link:

https://yourinstance.service-now.com/get_file.do?name=filename.doc

That’s all! You can use the link on all places in the instance and I think it could be really helpful, as it will give you quick access to specific file(s). Please note that Service Now is not meant as a file storage system, so if you have a lot of files that should be stored it is better to consider alternative solutions for this.

I hope this blog article is helpful. If you may have questions, please let me know by sending me an email.

Good luck!
Kind regards,
Ben Hankel (.img[at].img)

Leave a Reply