Powershell Activity Output - The argument is null or empty.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-30-2018 06:41 AM
Hi all,
We have a powershell activity that does a change in the AD user and should pass back to ServiceNow either Pass or Fail.
however every time it passes:
<results probe_time="3937" result_code="0">
<result execution_time="3625" payload_processing_time="0" raw_output_size="77">
<output> </output>
<hresult>-2146233087</hresult>
<error>
The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.Stack Trace: at System.Management.Automation.ValidateNotNullOrEmptyAttribute.Validate(Object arguments, EngineIntrinsics engineIntrinsics)at System.Management.Automation.ParameterBinderBase.BindParameter(CommandParameterInternal parameter, CompiledCommandParameter parameterMetadata, ParameterBindingFlags flags)
</error>
Below is the script we have in the Post Processing and the powershell script is attached.
Post Processing:
if(!gs.nil(executionResult.errorMessages)) {
activityOutput.result = "failure";
activityOutput.errorMessage = executionResult.errorMessages;
gs.info('---> ATC Name Change activityOutput.errorMessage: ' + activityOutput.errorMessage);
} else {
activityOutput.result = "success";
activityOutput.output = _trim(activityLocal.output);
gs.info('---> ATC Name Change activityLocal.output: ' + activityLocal.output);
}
function _trim(str) {
var objectguid_index = 0;
var objectguid_end = 0;
var c=activityOutput.status;
var a=activityOutput.result;
var b=activityOutput.errorMessage;
gs.log("esha1 result"+a);
gs.log("esha2 result"+b);
gs.log("esha result"+c);
//This will get the ObjectGUID value for output
var objectguid_start = /","GUID":"/g;
while (objectguid_start.test(str)==true)
{
objectguid_index = objectguid_start.lastIndex;
}
ldap_index = ldap_source_lng + 14;
objectguid_end = ldap_index * -1;
gs.log("objectguid_index "+ objectguid_index,"EB");
gs.log("objectguid_end "+ objectguid_end,"EB");
var objectguid = str.slice(objectguid_index,objectguid_end);
activityOutput.status = objectguid;
var result = str;
return result;
/*This will get the ObjectGUID value for output
var objectguid_start = /","GUID":"/g;
while (objectguid_start.test(str)==true)
{
objectguid_index = objectguid_start.lastIndex;
}
objectguid_end = ldap_index * -1;
var objectguid = str.slice(objectguid_index,objectguid_end);
activityOutput.status = objectguid; */
}
- Labels:
-
Orchestration (ITOM)
-
Service Mapping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2019 11:53 AM
Take a look in your system logs (syslog table) in ServiceNow around the time of this error occurring. You should see a Warning log showing which line of code may be causing the issue.
I am currently troubleshooting this issue as well. In my logs I see this in one of my Warning level messages:
org.mozilla.javascript.EcmaError: The undefined value has no properties.
Caused by error in sys_trigger.377feec4db72eb84814e5058dc961978 at line 2
1: if (gs.nil(executionResult.error)) {
==> 2: activityOutput.result = "success";
Even though we see this error, I am successfully showing an output value within my result object in the ECC Queue record.
We used to have a blank output within the ECC Queue record as well. It ended up being that the PowerShell script within ServiceNow (ecc_agent_script_file) did not have a '.ps1' at the end of the name. This seems to be due to the 'Execution Command' in the PowerShell activity designer has 'Script type' as 'MID server script file', which means from the ecc_agent_script_file table. I am assuming it needs to know the type of file it is running, or needs to be marked as a PowerShell executable, by including a PowerShell extension onto the name, such as ps1.
Hope this gets you started to a resolution.