Highlighted
Trusted Contributor.. Trusted Contributor..
Trusted Contributor..
1148 views

Accessing PowerShell Scripts returnCode

I'm using the PowerShell Script operation to carry out remote PowerShell activities on a server. When I am trying to use a scriptlet on a step result to access the returnCode I get an error that the scriptletRawResult is not defined.

Scriptlet:
returnCode = parseInt(scriptletRawResult['returnCode']);

Error:
Scriptlet error at line 1.
Code: returnCode = parseInt(scriptletRawResult['returnCode']);
Details: ReferenceError: "scriptletRawResult" is not defined in  at line number 1
In step PowerShell Script

How can I retrieve the returnCode from the operation via scriptlet?
Note I'm using the returnResult field as the 'From' parameter in the step result so I cannot access via scriptletInput.

Thanks

0 Likes
4 Replies
Highlighted
Outstanding Contributor.
Outstanding Contributor.

Re: Accessing PowerShell Scripts returnCode

Try scriptletContext.get("returnCode") if you are on a result filter.

Also worth knowing about this document in case you are not familiar about its existance.

If it does not work more details: screenshots of where exactly and how exactly you are using it will be needed

hope it helps,

Andrei Vasile Truta
0 Likes
Highlighted
Trusted Contributor.. Trusted Contributor..
Trusted Contributor..

Re: Accessing PowerShell Scripts returnCode

I also tried scriptletContext.get("returnCode") which didn't work either. Instead of returning a scriptlet error I either get a blank value or 'undefined' depending on whether I'm using Rhino or Nashorn.
Note that when using scriptletContext.get(), it's not just the returnCode which produces this behaviour but all other result fields behave in the same way.

I'm not doing anything advanced, simply create a new flow and add the PowerShell Script operation, wiring up the transitions to success and failure responses.
Remove all inputs from the PowerShell script step, apart from script and populate it with Get-Host
Add a step result, and add a scriptlet filter consisting of scriptletResult = scriptletRawResult["returnCode"];
Run the flow and observe the error message.

You can see the attached screenshots with this info., I also should point out tha I'm using HP OO Studio 10.70 Build 16.

0 Likes
Highlighted
Super Contributor.
Super Contributor.

Re: Accessing PowerShell Scripts returnCode

I believe we have seen this same issue.  The work around for us is to set the return code in the script and return that information.  From there the returnResult is filtered to get the information. 

Example in the PowerShell to return the return code and a return message:

  $ReturnCode   = 2
  $ReturnString = "Errror Message"
  $results | Add-Member -MemberType NoteProperty -Name "returnCode" -Value $ReturnCode
  $results | Add-Member -MemberType NoteProperty -Name "returnResults" -Value $ReturnString 

  return $results

 

0 Likes
Highlighted
Trusted Contributor.. Trusted Contributor..
Trusted Contributor..

Re: Accessing PowerShell Scripts returnCode

I have managed to work around it for now by adding a new step result (sr_returnCode) that gets its value from the returnCode result field. I am then able to access the return code in a scriptlet on another step result by using scriptletContext.get("sr_returnCode");

In your example I would need to know what the return code and error message should be in order to output the result but I want PowerShell to deal with that and pass the info to OO. You can see it does do this when looking at the raw result in the step result inspector., for some reason though, they just don't seem to be accessible by a scriptlet.

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.