Instatiate a Probe via Script (Business Rule)

mahmoudhabiball
Giga Contributor

Hi,

I am new to ServiceNow and I could find no right solution for my Problem (Out of the box)

I have defined a PowershellProbe with a script which recieves a Parameter (powershell_param_someparam).

Running the Script from on the GUI works successfully, yet I have no idea how would I be able to Access and Trigger this Pobe from a bussiness rule or another script type.

Is there any way to do it?

1 ACCEPTED SOLUTION

mahmoudhabiball
Giga Contributor

So,


there is no out of the box solution for this. An update set like the one described here by John j. Andersen needs to be loaded: http://www.john-james-andersen.com/blog/service-now/powershell-probe-and-utility-for-servicenow.html


View solution in original post

12 REPLIES 12

Jag5
Tera Guru

Hello Mahmoud,



You can write a script include and call the script from business rule. Below is the example.



PowerShellExecScript: function(scriptName, inputsJson) {


              var midServer = gs.getProperty('mid.server.rba_default');


var grScriptRecord = new GlideRecord('ecc_agent_script_file');


grScriptRecord.addQuery('name', scriptName);


var script;


grScriptRecord.query();


if (grScriptRecord.next()){


      script = grScriptRecord.script;


gs.log('PowerShellExecScript: found script ' + scriptName);


}


else {


gs.log('PowerShellExecScript:Cannot locate script ' + scriptRecord );


}



var inputsObj =   new global.JSON().decode(inputsJson);



var scriptParamed= script;



for(var propertyName in inputsObj) {


scriptParamed= scriptParamed.replace('%%SN:' + propertyName + '%%',inputsObj[propertyName]);


      }



var psProbe= new PowershellProbe( midServer, '127.0.0.1');


psProbe.setScript(scriptParamed);


var psResponse = psProbe.execute(true);


gs.log('Executed powershell probe');


gs.log('PowerShellProbe:'+ scriptName.toString()   +'\n\tOutput: ' + psResponse.output + '\n\tError: ' + psResponse.error);


gs.log('Executed PS script ' + scriptName + '\nOutput: ' + psResponse.output );



return psResponse.output;


},



Thanks,


Jag.



Please mark correct/helpful as needed.


This line is my Problem: var psProbe= new PowershellProbe( midServer, '127.0.0.1');



The script doesn't continue processing the script after this line. Do I Need to install any Feature or enable any plugin to be able to instantiate a PowershellProbe object?


Hello Mahmoud,



Would you be able to provide your code. So, that i can check it.



Thanks,


Jag.


Is is not about the script. Every time I try to instantiate the Powershell Object, the script Fails. The breakpoint is being and it Fails after that.



so a script like this one   in a Business rule would fail:



(function executeRule(current, previous /*null when async*/) {



var psProbe= new PowershellProbe( "mid.server.midserver_scom", '127.0.0.1');



})(current, previous);