2

Is there a way to run the JavaScript file on a schedule, without access to the server (there is no access to the CA and to the server, only the rights of the web application administrator, the administrator rights of the site collection are not)?

It is possible so?:

Start-Process -FilePath \\server\sites\test\logo\Plugins\Items.js

or

Cscript.exe "\\server\sites\test\logo\Plugins\Items.js"
  • what will this JS do? do you have a right to develop and deploy a timer job? – Mohamed El-Qassas MVP Sep 11 '17 at 15:40
  • @M.Qassas Unfortunately no access. – Shrek Sep 11 '17 at 18:56
3

It sounds like a very weird case, but you can still do it.

Very roughly, this is what it takes:

  • Create a separate SharePoint page with a Content Editor Web Part (CEWP)
  • Optional. Make sure this page can only be accessed by certain accounts
  • Add your script to the CEWP.
  • Create a PowerShell file (.ps1) that will open your SharePoint page with the script

    $IE=new-object -com internetexplorer.application; $IE.navigate2("http://portal/pages/page_with_a_script/script.js"); $IE.visible=$true

  • Create a windows scheduled job that runs this .ps1 file on a schedule

3

I like the powershell approach mentioned by Denis, but I'd go further and code the powershell to just do the task that is done by the js. Having a visible IE window run by a process that should be able to run with no one logged in is going to surprise any admins who need to work with this script.

  • 1
    Exactly, it should be the answer. But who knows, maybe this JavasSript is 3000 lines of very unique code that will take days to rewrite in PowerShell – Denis Molodtsov Sep 11 '17 at 19:35
  • Start-Process -FilePath \\server\sites\test\logo\Plugins\Items.js? – Shrek Sep 12 '17 at 11:13
  • JavaScript needs some sort of a host to actually run it. Examples include the browser, node.js, and cscript.exe. (cscript is an old method that was traditionally used to run vbs files). So you wouldn't be starting the process as js, but rather, you'd need to start one of the hosts, and tell the host to "run" the js file. Denis's answer uses the browser: so powershell runs the browser, and then tells the browser to run a page that references the js file. Here's an example for node.js: stackoverflow.com/questions/6737824/… – Mike2500 Sep 12 '17 at 12:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.