Invoke windows commands from RTC javascript
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.
dojo.provide("com.test.providers.script.ValidateStatetoDeploy");
dojo.require("com.ibm.team.workitem.api.common.Status");
dojo.require("com.ibm.team.workitem.api.common.Severity");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
dojo.require("dojo.data.ItemFileWriteStore");
(function() {
var vStatus = com.ibm.team.workitem.api.common.Status;
var Severity = com.ibm.team.workitem.api.common.Severity;
var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
dojo.declare("com.test.providers.script.ValidateStatetoDeploy", null, {
validate: function(attributeId, workItem, configuration) {
if (workItem.getValue(WorkItemAttributes.TYPE) === "com.ibm.team.workItemType.buildtrackingitem" && workItem.getValue(WorkItemAttributes.STATE) === "com.ibm.team.workitem.buildTrackingWorkflow.state.s3") {
//invoke windows command here
try{
var shell = WScript.CreateObject("WScript.Shell");
} catch(err){
console.log(err);
}
shell.Run("echo > C:\tmp\validatefile.txt");
/* try{
var wsh = new ActiveXObject("WScript.Shell");
}catch(err){
console.log(err);
}
wsh.Run("echo > C:\tmp\validateFile.txt");
*/
return vStatus.OK_STATUS;
} else {
var serverity = configuration.getChild("parameters").getStringDefault("severity", Severity.ERROR.name);
var message = configuration.getChile("parameters").getStringDefault("message", "");
return new vStatus(Severity[severity], message);
}
}
});
})();
3 answers
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.
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(ScriptRuntime.java:3557)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3535)
...
com.ibm.team.rtc.common.scriptengine.UnknownTypeException: 'com.test.providers.script.ValidateStatetoDeploy' is not a constructor
at com.ibm.team.rtc.common.scriptengine.environment.ScriptingHelperImplementation.getConstructor(ScriptingHelperImplementation.java:162)
at com.ibm.team.rtc.common.scriptengine.ScriptUtilities$1.run(ScriptUtilities.java:30)
at com.ibm.team.rtc.common.scriptengine.environment.AbstractScriptEnvironment.execute(AbstractScriptEnvironment.java:74)
at com.ibm.team.rtc.common.scriptengine.ScriptUtilities.newInstance(ScriptUtilities.java:27)