Powershell Studio removing part of code after loading form

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST SUBSCRIPTION NUMBERS, LICENSE KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
ctc_rl008
Posts: 5
Joined: Wed Jul 02, 2014 6:42 am

Powershell Studio removing part of code after loading form

Post by ctc_rl008 » Tue Oct 29, 2019 3:47 am

To help you better we need some information from you.

*** Please fill in the fields below. If you leave fields empty or specify 'latest' rather than the actual version your answer will be delayed as we will be forced to ask you for this information. ***

Product, version and build: Powershell Studio 2019 5.6.167
32 or 64 bit version of product: 64-bit
Operating system: Windows 10 1803
32 or 64 bit OS: 64-bit

*** Please add details and screenshots as needed below. ***

Hello, i have an issue with Powershell studio saving a form it cuts off some code attached to a button. The script itself works without a problem.
  1. # Details of the runbook we are going to run
  2.  
  3. $rbid = "abf850c5-24ba-4d2f-84fb-5eefee0bcab8"
  4.  
  5. $rbParameters = @{ "a04171a9-5f99-48da-b0ce-4c62cd7c6029" = "$Global:var_computer"; "3ca59135-5ebe-4e76-a4a5-920b5bf259ba" = $Global:var_ticket; "3840ea3d-5725-45ff-83a7-4cab2b154de8" = $Global:var_user }
  6.  
  7.  
  8.  
  9. # Create the request object
  10.  
  11. $request = [System.Net.HttpWebRequest]::Create("http://******:81/Orchestrator2012/Orchestrator.svc/Jobs")
  12.  
  13.  
  14.  
  15. # Set the credentials to default or prompt for credentials
  16.  
  17. $request.UseDefaultCredentials = $true
  18.  
  19. #$request.Credentials = Get-Credential
  20.  
  21.  
  22.  
  23. # Build the request header
  24.  
  25. $request.Method = "POST"
  26.  
  27. $request.UserAgent = "Microsoft ADO.NET Data Services"
  28.  
  29. $request.Accept = "application/atom+xml,application/xml"
  30.  
  31. $request.ContentType = "application/atom+xml"
  32.  
  33. $request.KeepAlive = $true
  34.  
  35. $request.Headers.Add("Accept-Encoding", "identity")
  36.  
  37. $request.Headers.Add("Accept-Language", "en-US")
  38.  
  39. $request.Headers.Add("DataServiceVersion", "1.0;NetFx")
  40.  
  41. $request.Headers.Add("MaxDataServiceVersion", "2.0;NetFx")
  42.  
  43. $request.Headers.Add("Pragma", "no-cache")
  44.  
  45.  
  46.  
  47. # If runbook servers are specified, format the string
  48.  
  49. $rbServerString = ""
  50.  
  51. if (-not [string]::IsNullOrEmpty($RunbookServers))
  52.  
  53. {
  54.  
  55.     $rbServerString = -join ("<d:RunbookServers>", $RunbookServers, "</d:RunbookServers>")
  56.  
  57. }
  58.  
  59.  
  60.  
  61. # Format the Runbook parameters, if any
  62.  
  63. $rbParamString = ""
  64.  
  65. if ($rbParameters -ne $null)
  66.  
  67. {
  68.  
  69.    
  70.  
  71.     # Format the param string from the Parameters hashtable
  72.  
  73.     $rbParamString = "<d:Parameters><![CDATA[<Data>"
  74.  
  75.     foreach ($p in $rbParameters.GetEnumerator())
  76.  
  77.     {
  78.  
  79.         #$rbParamString = -join ($rbParamString,"&lt;Parameter&gt;&lt;ID&gt;{",$p.key,"}&lt;/ID&gt;&lt;Value&gt;",$p.value,"&lt;/Value&gt;&lt;/Parameter&gt;")        
  80.  
  81.         $rbParamString = -join ($rbParamString, "<Parameter><ID>{", $p.key, "}</ID><Value>", $p.value, "</Value></Parameter>")
  82.  
  83.     }
  84.  
  85.     $rbParamString += "</Data>]]></d:Parameters>"
  86.  
  87. }
  88.  
  89.  
  90.  
  91. # Build the request body
  92.  
  93. $requestBody = @"
  94.  
  95. <?xml version="1.0" encoding="utf-8" standalone="yes"?>
  96.  
  97. <entry xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
  98.  
  99.    <content type="application/xml">
  100.  
  101.        <m:properties>
  102.  
  103.            <d:RunbookId m:type="Edm.Guid">$rbid</d:RunbookId>
  104.  
  105.            $rbserverstring
  106.  
  107.            $rbparamstring
  108.  
  109.        </m:properties>
  110.  
  111.    </content>
  112.  
  113. </entry>
  114.  
  115. "@
  116.  
  117.  
  118.  
  119. # Create a request stream from the request
  120.  
  121. $requestStream = new-object System.IO.StreamWriter $Request.GetRequestStream()
  122.  
  123.  
  124.  
  125. # Sends the request to the service
  126.  
  127. $requestStream.Write($RequestBody)
  128.  
  129. $requestStream.Flush()
  130.  
  131. $requestStream.Close()
  132.  
  133.  
  134.  
  135. # Get the response from the request
  136.  
  137. [System.Net.HttpWebResponse]$response = [System.Net.HttpWebResponse]$Request.GetResponse()
  138.  
  139.  
  140.  
  141. # Write the HttpWebResponse to String
  142.  
  143. $responseStream = $Response.GetResponseStream()
  144.  
  145. $readStream = new-object System.IO.StreamReader $responseStream
  146.  
  147. $responseString = $readStream.ReadToEnd()
  148.  
  149.  
  150.  
  151. # Close the streams
  152.  
  153. $readStream.Close()
  154.  
  155. $responseStream.Close()
  156.  
  157.  
  158.  
  159. # Get the ID of the resulting job
  160.  
  161. if ($response.StatusCode -eq 'Created')
  162.  
  163. {
  164.  
  165.     $xmlDoc = [xml]$responseString
  166.  
  167.     $jobId = $xmlDoc.entry.content.properties.Id.InnerText
  168.  
  169.     Write-Host "Successfully started runbook. Job ID: " $jobId
  170.  
  171. }
  172.  
  173. else
  174.  
  175. {
  176.  
  177.     Write-Host "Could not start runbook. Status: " $response.StatusCode
  178.  
  179. }

The problem happens when i link the above code to a button, launching the form works until i save it. Once saved and opened again Powershell studio decides to remove part of the code. When i load the project again this is what remains from the above script:
  1. $rbid = "7810ee58-6970-4f74-b00c-4f107f638608"
  2.  
  3.     $rbParameters = @{ "161a1de9-712b-457e-adec-47840fb86dc0" = "$Global:var_computer"; "b183de03-3248-49e1-bfa8-d1cfd0727d12" = "$Global:var_ticket" }
  4.  
  5.    
  6.  
  7.     # Create the request object
  8.  
  9.     $request = [System.Net.HttpWebRequest]::Create("*******:81/Orchestrator2012/Orchestrator.svc/Jobs")
  10.  
  11.    
  12.  
  13.     # Set the credentials to default or prompt for credentials
  14.  
  15.     $request.UseDefaultCredentials = $true
  16.  
  17.     #$request.Credentials = Get-Credential
  18.  
  19.    
  20.  
  21.     # Build the request header
  22.  
  23.     $request.Method = "POST"
  24.  
  25.     $request.UserAgent = "Microsoft ADO.NET Data Services"
  26.  
  27.     $request.Accept = "a[Codebox=powershell file=Untitled.ps1]pplication/atom+xml,application/xml"
  28.  
  29.     $request.ContentType = "application/atom+xml"
  30.  
  31.     $request.KeepAlive = $true
  32.  
  33.     $request.Headers.Add("Accept-Encoding", "identity")
  34.  
  35.     $request.Headers.Add("Accept-Language", "en-US")
  36.  
  37.     $request.Headers.Add("DataServiceVersion", "1.0;NetFx")
  38.  
  39.     $request.Headers.Add("MaxDataServiceVersion", "2.0;NetFx")
  40.  
  41.     $request.Headers.Add("Pragma", "no-cache")
  42.  
  43.    
  44.  
  45.     # If runbook servers are specified, format the string
  46.  
  47.     $rbServerString = ""
  48.  
  49.     if (-not [string]::IsNullOrEmpty($RunbookServers))
  50.  
  51.     {
  52.  
  53.         $rbServerString = -join ("<d:RunbookServers>", $RunbookServers, "</d:RunbookServers>")
  54.  
  55.     }
  56.  
  57.    
  58.  
  59.     # Format the Runbook parameters, if any
  60.  
  61.     $rbParamString = ""
  62.  
  63.     if ($rbParameters -ne $null)
  64.  
  65.     {
  66.  
  67.        
  68.  
  69.         # Format the param string from the Parameters hashtable
  70.  
  71.         $rbParamString = "<d:Parameters><![CDATA[<Data>"
  72.  
  73.         foreach ($p in $rbParameters.GetEnumerator())
  74.  
  75.         {
  76.  
  77.             #$rbParamString = -join ($rbParamString,"&lt;Parameter&gt;&lt;ID&gt;{",$p.key,"}&lt;/ID&gt;&lt;Value&gt;",$p.value,"&lt;/Value&gt;&lt;/Parameter&gt;")        
  78.  
  79.             $rbParamString = -join ($rbParamString, "<Parameter><ID>{", $p.key, "}</ID><Value>", $p.value, "</Value></Parameter>")
  80.  
  81.         }
  82.  
  83.         $rbParamString += "</Data>]]
So saving each time removes everything coming after $rbParamString += "</Data>]]

When i save it as a script (ps1) it leaves the code as it is after loading it again.

Any idea what could be causing this?
Attachments
2019-10-29 11_39_12-SAPIEN PowerShell Studio 2019.png
2019-10-29 11_39_12-SAPIEN PowerShell Studio 2019.png (14.15 KiB) Viewed 1939 times

User avatar
brittneyr
Site Admin
Posts: 235
Joined: Thu Jun 01, 2017 7:20 am

Re: Powershell Studio removing part of code after loading form

Post by brittneyr » Tue Oct 29, 2019 9:00 am

So far I have not been able to reproduce this behavior. Does this only occur with this file or does it happen with all files?

Can you please provide screenshots of the following:
-Editor Settings in Options
SPS_EditorSettings.png
SPS_EditorSettings.png (32.51 KiB) Viewed 1919 times
-Format settings in Options
SPS_FormattingSettings.png
SPS_FormattingSettings.png (40.23 KiB) Viewed 1919 times
-Character Encoding from the status bar at the bottom of the application
SPS_Encoding.png
SPS_Encoding.png (17.89 KiB) Viewed 1919 times
Brittney Ryn
SAPIEN Technologies, Inc.

User avatar
ctc_rl008
Posts: 5
Joined: Wed Jul 02, 2014 6:42 am

Re: Powershell Studio removing part of code after loading form

Post by ctc_rl008 » Tue Oct 29, 2019 11:53 pm

Thanks for you response.
I checked all settings and they seem to be identical to yours.

This only happens when i use this code in a .psf file. I have created a few new forms and it happens in any of them. When i save it as .ps1 it doesn't happen.
I never had this kind of behavior in any other projects.

User avatar
brittneyr
Site Admin
Posts: 235
Joined: Thu Jun 01, 2017 7:20 am

Re: Powershell Studio removing part of code after loading form

Post by brittneyr » Wed Oct 30, 2019 8:03 am

Can you please upload one of the forms that is having the issue here:
https://www.sapien.com/support/upload
Brittney Ryn
SAPIEN Technologies, Inc.

User avatar
ctc_rl008
Posts: 5
Joined: Wed Jul 02, 2014 6:42 am

Re: Powershell Studio removing part of code after loading form

Post by ctc_rl008 » Thu Oct 31, 2019 6:30 am

File uploaded

User avatar
ctc_rl008
Posts: 5
Joined: Wed Jul 02, 2014 6:42 am

Re: Powershell Studio removing part of code after loading form

Post by ctc_rl008 » Thu Oct 31, 2019 8:12 am

Meanwhile i have figured out a work around by placing the code in a function which i saved as ps1. When the button is clicked the variables are passed as parameters to the external ps1 file and i have added it as dot source to call it ( . .\script.ps1)
This does the trick, PSS has no issue with the code in either a ps1 or module file.

User avatar
brittneyr
Site Admin
Posts: 235
Joined: Thu Jun 01, 2017 7:20 am

Re: Powershell Studio removing part of code after loading form

Post by brittneyr » Thu Oct 31, 2019 9:37 am

Thank you, I have received your file and I will continue to investigate this issue. When I get any information, I'll post here.
Brittney Ryn
SAPIEN Technologies, Inc.

User avatar
brittneyr
Site Admin
Posts: 235
Joined: Thu Jun 01, 2017 7:20 am

Re: Powershell Studio removing part of code after loading form

Post by brittneyr » Thu Oct 31, 2019 10:16 am

I have been able to replicate your issue. I have filed an internal bug report with the development team.
Brittney Ryn
SAPIEN Technologies, Inc.

User avatar
brittneyr
Site Admin
Posts: 235
Joined: Thu Jun 01, 2017 7:20 am

Re: Powershell Studio removing part of code after loading form

Post by brittneyr » Mon Nov 04, 2019 3:22 pm

This issue has been resolved in build 5.6.170.
Brittney Ryn
SAPIEN Technologies, Inc.