It's all about the answers!

Ask a question

Invoke windows commands from RTC javascript

Frederick Ho (112) | asked Jul 16 '15, 4:36 p.m.

Hi all,

    I am trying to invoke a simple windows command from javascript within RTC and was unsuccessful.  This command is invoked when the buildtrackingitem entered "Declare Green" state.  I tried WScript.Shell but not working so far.  Please see the script snippet below for more details.  Any suggestion/help would be much appreciated.




(function() {
    var vStatus =;
    var Severity =;
    var WorkItemAttributes =;
    dojo.declare("com.test.providers.script.ValidateStatetoDeploy", null, {

    validate: function(attributeId, workItem, configuration) {
 if (workItem.getValue(WorkItemAttributes.TYPE) === "" && workItem.getValue(WorkItemAttributes.STATE) === "") {

  //invoke windows command here
  var shell = WScript.CreateObject("WScript.Shell");
  } catch(err){

  shell.Run("echo > C:\tmp\validatefile.txt");
/*  try{
  var wsh = new ActiveXObject("WScript.Shell"); 

  wsh.Run("echo > C:\tmp\validateFile.txt");

  return vStatus.OK_STATUS;

 } else {
  var serverity = configuration.getChild("parameters").getStringDefault("severity",;
  var message = configuration.getChile("parameters").getStringDefault("message", "");
  return new vStatus(Severity[severity], message); 

3 answers

permanent link
Simon Washbrook (67216) | answered Jul 17 '15, 2:49 a.m.
When you say it does not work, how do you know? What error message do you see in the log file?
IMHO the object "ActiveXObject" only exists in Microsoft's JavaScript engine which is not the javaScript engine being used by RTC.

permanent link
Donald Nong (14.5k414) | answered Jul 20 '15, 3:19 a.m.
There are a few things to consider.
1. ActiveX may not work properly in browsers other than IE.
2. The script will most likely be executed twice - once on the client side (by the browser JavaScript engine), and another time on the server side (by the RTC/Eclipse JavaScript engine).
3. You may need to escape the backslash, or use forward slash instead.

permanent link
Frederick Ho (112) | answered Jul 22 '15, 2:02 p.m.

Thanks Simon and Donald for the replies.  I have made the change to the script using / instead of \ as mentioned by Donald.  I still keep getting the same errors of "document" is not defined and com.test.providers.script.ValidateStatetoDeploy is not a constructor.  Please advise.  Thanks

Error executing script validatestatetodeploy.js

org.mozilla.javascript.EcmaError: ReferenceError: "document" is not defined. ({"Bundle-SymbolicName":"org.dojotoolkit.dojo", "path":"resources", "name":"dojo.js"}#313(Function)#1(eval)#1)
at org.mozilla.javascript.ScriptRuntime.constructError(
at org.mozilla.javascript.ScriptRuntime.constructError(

... 'com.test.providers.script.ValidateStatetoDeploy' is not a constructor

Donald Nong commented Jul 24 '15, 3:12 a.m.

Don't waste your time on it.
I can confirm that both Firefox and Chrome with the default configuration cannot create a WScript host. I also tried briefly with IE 11 and it could not be created either (probably because I have not tried hard enough).
Calling a native command from the browser sounds like a security risk. Do you mind telling us what you're trying to do and why you've come up with such an idea?

Frederick Ho commented Jul 24 '15, 11:37 a.m.

Thanks for trying out the options Donald.  I will give it a day or two then call it off. 

We were trying to automate the build/deploy process using RTC build engine and Maven repository for staging.  Instead of running the Maven commend manually, we like to see if we can initiate the Maven commend from state change action of RTC track build work item.  Does it make sense?   

Your answer

Register or to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.