0 votes
1 view
in RPA by (12.8k points)

I am trying to get a value from an input box from a Powershell script back to a UI Path Sequence. I have created a simple sequence as an example. Yes, I know I could do this all in UI Path, I am just using an easy example as a way to try and test this for future use cases. Here is my sequence:

sequence

My text file from "Read text file" is:

$test = "Desktop/PassingArgs2of2.ps1 -Message foo"

Invoke-Expression -Command $test

The activity in UiPath looks like so:

Read Text File

The psCmd that I am running in the Invoke power shell activity looks like this:

Param(

[parameter(Mandatory=$true)]

[string]

$Message)

try{

   $Global:fooVar = $null

    function Test-InputBox(){

        [void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')

        $msg = "fooMsg"

        $title = "fooTitle"

        $localtest = [Microsoft.VisualBasic.Interaction]::InputBox($msg, $title)

        $Global:fooVar = $localtest.ToString()

    }

    Test-InputBox

}

catch{}

I tried setting fooVar equal to testLocal in the PowerShell Variables within Invoke power shell and then writing it, but that did not work.

fooVar

Basically I want to get fooVar back into UI Path. Any help would be greatly appreciated. Thank you!

1 Answer

0 votes
by (29.8k points)

hi, you are very close to solution, first thing you need to do is add a return function to your poweshell script, you can refer to the code below  

[void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')

$title = 'Your title goes here'
$msg   = 'Your favorite player:'

$text = [Microsoft.VisualBasic.Interaction]::InputBox($msg, $title)
return $text

Then, just use this script directly in the Invoke Powershell activity. Note that the most important part here is the Output property, you can just access the text provided by the user by accessing output(0).ToString().

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...