- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2018 06:36 AM
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?
Solved! Go to Solution.
- Labels:
-
Best Practices
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2018 12:29 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2018 08:04 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2018 01:39 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2018 06:20 AM
Hello Mahmoud,
Would you be able to provide your code. So, that i can check it.
Thanks,
Jag.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2018 06:28 AM
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);