function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Winsoft Tech.Winsoft Tech. 

How to upload .js file

How can  I upload my own .js file on and how to use it in Custom s-control.
I want to upload that .js file for displaying data in the grid from database.
Upload the .js file as a document, then simply reference the document Id in your script declaration.
<script src="/servlet/servlet.FileDownload?file=[document Id here]"></script>

Greg HGreg H
I add the js code as an sControl and then reference the sControl in a script tag at the top of the document.  This eliminates anyone seeing it in the documents folder.


<script src="/servlet/servlet.Integration?lid={sControlId}" type="text/javascript"></script>
Hope this helps,
Ron HessRon Hess
you can also create an scontrol of type "Snippet" and load your JS file there, and include it from any other scontrol

Since this thread is still one of the top responses in a search for including a .js file in an S-Control, I thought I would contribute my thoughts on the best practice for doing so.


Building on Ron's suggestion, create a new S-Control of type "Snippet" and paste your javascript code in the snippet.  Be sure to wrap your JS code in the script tags as below:



<script type="text/javascript">

// My Javascript Code



 After that, you can easily include your new S-Control by name using an "INCLUDE".  For example, if I named my new  Snippet S-Control "FooJS", I would do the include in my S-Controls using the included JS as follows:



{! INCLUDE($SControl.FooJS)}


I believe this is superior to the approaches using a document ID or sControlID because it will work in both Sandbox and production orgs without updating the IDs.






Hi, I'm trying to get somthing like this to work


and already try this solution but it doesn't work at all,


any ideas ?