
Aparna Singireddy (Customer) asked a question.
I'm trying to add a powershell script that extracts a field from macro full path.
When I give a hardcoded path for $nullpath, script returns correct plannumber but when I call it using macro it just returns a blank field. I've tried using double quotes around the full path and still the same result.
$nullpath = $miaclient.MIMacro('[FullPath]')
$path = $nullPath.Split("/")
$plannumber = $path[3]
$miaclient.MISetTaskParam("plannumber","$plannumber")
I think there must be something else going on there...I just tried your command and it worked for me:
$nullpath = $miaclient.MIMacro('[FullPath]')
$miaclient.MILogMsg($nullpath)
Try adding a MILogMsg after each variable is set to make sure it's returning what you think.
I have "replicated" your issue. The "Split" function builds an array starting at 0 for the first element. Here is the quick code I wrote:
$fullPath = $miaclient.MIMacro("[FullPath]")
$path = $fullPath.Split("/")
$miaclient.MILogMsg("Path: $($fullPath)")
$miaclient.MILogMsg("0: $($path[0])")
$miaclient.MILogMsg("1: $($path[1])")
$miaclient.MILogMsg("2: $($path[2])")
$miaclient.MILogMsg("3: $($path[3])")
And here are the logs:
PSTestMIMacro !: Path: E:/TestDir/TestFile.txt
PSTestMIMacro !: 0: E:
PSTestMIMacro !: 1: TestDir
PSTestMIMacro !: 2: TestFile.txt
PSTestMIMacro !: 3:
Use $path[2] instead of $path[3]