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 LICENSE NUMBERS, ACTIVATION 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.
This topic is 4 years and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
ctc_rl008
Posts: 8
Last visit: Wed Apr 26, 2023 10:11 pm

Powershell Studio removing part of code after loading form

Post by ctc_rl008 »

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. $rbid = "abf850c5-24ba-4d2f-84fb-5eefee0bcab8"
  3. $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 }
  4.  
  5. # Create the request object
  6. $request = [System.Net.HttpWebRequest]::Create("http://******:81/Orchestrator2012/Orchestrator.svc/Jobs")
  7.  
  8. # Set the credentials to default or prompt for credentials
  9. $request.UseDefaultCredentials = $true
  10. #$request.Credentials = Get-Credential
  11.  
  12. # Build the request header
  13. $request.Method = "POST"
  14. $request.UserAgent = "Microsoft ADO.NET Data Services"
  15. $request.Accept = "application/atom+xml,application/xml"
  16. $request.ContentType = "application/atom+xml"
  17. $request.KeepAlive = $true
  18. $request.Headers.Add("Accept-Encoding", "identity")
  19. $request.Headers.Add("Accept-Language", "en-US")
  20. $request.Headers.Add("DataServiceVersion", "1.0;NetFx")
  21. $request.Headers.Add("MaxDataServiceVersion", "2.0;NetFx")
  22. $request.Headers.Add("Pragma", "no-cache")
  23.  
  24. # If runbook servers are specified, format the string
  25. $rbServerString = ""
  26. if (-not [string]::IsNullOrEmpty($RunbookServers))
  27. {
  28.     $rbServerString = -join ("<d:RunbookServers>", $RunbookServers, "</d:RunbookServers>")
  29. }
  30.  
  31. # Format the Runbook parameters, if any
  32. $rbParamString = ""
  33. if ($rbParameters -ne $null)
  34. {
  35.    
  36.     # Format the param string from the Parameters hashtable
  37.     $rbParamString = "<d:Parameters><![CDATA[<Data>"
  38.     foreach ($p in $rbParameters.GetEnumerator())
  39.     {
  40.         #$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;")        
  41.         $rbParamString = -join ($rbParamString, "<Parameter><ID>{", $p.key, "}</ID><Value>", $p.value, "</Value></Parameter>")
  42.     }
  43.     $rbParamString += "</Data>]]></d:Parameters>"
  44. }
  45.  
  46. # Build the request body
  47. $requestBody = @"
  48. <?xml version="1.0" encoding="utf-8" standalone="yes"?>
  49. <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">
  50.    <content type="application/xml">
  51.        <m:properties>
  52.            <d:RunbookId m:type="Edm.Guid">$rbid</d:RunbookId>
  53.            $rbserverstring
  54.            $rbparamstring
  55.        </m:properties>
  56.    </content>
  57. </entry>
  58. "@
  59.  
  60. # Create a request stream from the request
  61. $requestStream = new-object System.IO.StreamWriter $Request.GetRequestStream()
  62.  
  63. # Sends the request to the service
  64. $requestStream.Write($RequestBody)
  65. $requestStream.Flush()
  66. $requestStream.Close()
  67.  
  68. # Get the response from the request
  69. [System.Net.HttpWebResponse]$response = [System.Net.HttpWebResponse]$Request.GetResponse()
  70.  
  71. # Write the HttpWebResponse to String
  72. $responseStream = $Response.GetResponseStream()
  73. $readStream = new-object System.IO.StreamReader $responseStream
  74. $responseString = $readStream.ReadToEnd()
  75.  
  76. # Close the streams
  77. $readStream.Close()
  78. $responseStream.Close()
  79.  
  80. # Get the ID of the resulting job
  81. if ($response.StatusCode -eq 'Created')
  82. {
  83.     $xmlDoc = [xml]$responseString
  84.     $jobId = $xmlDoc.entry.content.properties.Id.InnerText
  85.     Write-Host "Successfully started runbook. Job ID: " $jobId
  86. }
  87. else
  88. {
  89.     Write-Host "Could not start runbook. Status: " $response.StatusCode
  90. }

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.     $rbParameters = @{ "161a1de9-712b-457e-adec-47840fb86dc0" = "$Global:var_computer"; "b183de03-3248-49e1-bfa8-d1cfd0727d12" = "$Global:var_ticket" }
  3.    
  4.     # Create the request object
  5.     $request = [System.Net.HttpWebRequest]::Create("*******:81/Orchestrator2012/Orchestrator.svc/Jobs")
  6.    
  7.     # Set the credentials to default or prompt for credentials
  8.     $request.UseDefaultCredentials = $true
  9.     #$request.Credentials = Get-Credential
  10.    
  11.     # Build the request header
  12.     $request.Method = "POST"
  13.     $request.UserAgent = "Microsoft ADO.NET Data Services"
  14.     $request.Accept = "a[Codebox=powershell file=Untitled.ps1]pplication/atom+xml,application/xml"
  15.     $request.ContentType = "application/atom+xml"
  16.     $request.KeepAlive = $true
  17.     $request.Headers.Add("Accept-Encoding", "identity")
  18.     $request.Headers.Add("Accept-Language", "en-US")
  19.     $request.Headers.Add("DataServiceVersion", "1.0;NetFx")
  20.     $request.Headers.Add("MaxDataServiceVersion", "2.0;NetFx")
  21.     $request.Headers.Add("Pragma", "no-cache")
  22.    
  23.     # If runbook servers are specified, format the string
  24.     $rbServerString = ""
  25.     if (-not [string]::IsNullOrEmpty($RunbookServers))
  26.     {
  27.         $rbServerString = -join ("<d:RunbookServers>", $RunbookServers, "</d:RunbookServers>")
  28.     }
  29.    
  30.     # Format the Runbook parameters, if any
  31.     $rbParamString = ""
  32.     if ($rbParameters -ne $null)
  33.     {
  34.        
  35.         # Format the param string from the Parameters hashtable
  36.         $rbParamString = "<d:Parameters><![CDATA[<Data>"
  37.         foreach ($p in $rbParameters.GetEnumerator())
  38.         {
  39.             #$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;")        
  40.             $rbParamString = -join ($rbParamString, "<Parameter><ID>{", $p.key, "}</ID><Value>", $p.value, "</Value></Parameter>")
  41.         }
  42.         $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 4297 times
User avatar
brittneyr
Site Admin
Posts: 1671
Last visit: Tue Apr 16, 2024 8:16 am
Answers: 39
Been upvoted: 31 times

Re: Powershell Studio removing part of code after loading form

Post by brittneyr »

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 4277 times
-Format settings in Options
SPS_FormattingSettings.png
SPS_FormattingSettings.png (40.23 KiB) Viewed 4277 times
-Character Encoding from the status bar at the bottom of the application
SPS_Encoding.png
SPS_Encoding.png (17.89 KiB) Viewed 4277 times
Brittney
SAPIEN Technologies, Inc.
User avatar
ctc_rl008
Posts: 8
Last visit: Wed Apr 26, 2023 10:11 pm

Re: Powershell Studio removing part of code after loading form

Post by ctc_rl008 »

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: 1671
Last visit: Tue Apr 16, 2024 8:16 am
Answers: 39
Been upvoted: 31 times

Re: Powershell Studio removing part of code after loading form

Post by brittneyr »

Can you please upload one of the forms that is having the issue here:
https://www.sapien.com/support/upload
Brittney
SAPIEN Technologies, Inc.
User avatar
ctc_rl008
Posts: 8
Last visit: Wed Apr 26, 2023 10:11 pm

Re: Powershell Studio removing part of code after loading form

Post by ctc_rl008 »

File uploaded
User avatar
ctc_rl008
Posts: 8
Last visit: Wed Apr 26, 2023 10:11 pm

Re: Powershell Studio removing part of code after loading form

Post by ctc_rl008 »

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: 1671
Last visit: Tue Apr 16, 2024 8:16 am
Answers: 39
Been upvoted: 31 times

Re: Powershell Studio removing part of code after loading form

Post by brittneyr »

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
SAPIEN Technologies, Inc.
User avatar
brittneyr
Site Admin
Posts: 1671
Last visit: Tue Apr 16, 2024 8:16 am
Answers: 39
Been upvoted: 31 times

Re: Powershell Studio removing part of code after loading form

Post by brittneyr »

I have been able to replicate your issue. I have filed an internal bug report with the development team.
Brittney
SAPIEN Technologies, Inc.
User avatar
brittneyr
Site Admin
Posts: 1671
Last visit: Tue Apr 16, 2024 8:16 am
Answers: 39
Been upvoted: 31 times

Re: Powershell Studio removing part of code after loading form

Post by brittneyr »

This issue has been resolved in build 5.6.170.
Brittney
SAPIEN Technologies, Inc.
This topic is 4 years and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.