SitecorePowerShell / Console

Sitecore PowerShell Extensions
https://doc.sitecorepowershell.com/
Other
114 stars 70 forks source link

PowerShell - http request context issue #1113

Closed chris-madamba closed 6 months ago

chris-madamba commented 5 years ago

Expected Behavior

Executing a script using "Execute in http request context" will get selected language of the item.

Actual Behavior

"Execute in http request context" will currently only getting the default language of "en-US" using PowerShell ISE or executing script in the Content Tree using Context Menu

Steps to Reproduce the Problem

Sitecore PowerShell Extensions 5.0.0.42513 Sitecore 8.2 Windows PowerShell 5.1

Hello,

I currently have an Expand-Tokens script that runs as expected in the PowerShell ISE when using the "Execute in a background job" but when I attempt to execute the same script in the Sitecore Content Tree using the context menu the script always picks up the default language of en-US instead of the actual selected language of that Item (i.e. en-CA or fr-CA)

In the PowerShell ISE if I have a selected language: en-CA (English - Canada) and a Sitecore Content Item selected. When running the script as "Execute in a background job" the correct language item gets update using the Expand-Tokens function.

If I attempt to execute the same script using the "Execute in http request context" only the default language (en - United States) gets updated regardless if the correct language is selected (en-CA). This is also the case when attempting to execute the script in the Sitecore Content Tree using the PowerShell Extensions from the context menu.

I've attached screen shots for reference.

Is there a way to make sure that the PSE picks up the selected language for the selected Sitecore item?

Thanks!

PS-Extension-http-request

PS_ISE_-_Background

michaellwest commented 5 years ago

@chris-madamba Thinking more about your problem and with some digging in, the most resilient solution would be to provide the language to Get-Item using the -Language parameter.

Some options to achieve this could be:

github-actions[bot] commented 6 months ago

This issue is stale because it has been open for 365 days with no activity.

AdamNaj commented 6 months ago

Use the $SitecoreContextItem rather than Get-Item . to retrieve the item in the context language. This will work in ISE starting with SPE 8.0 due to the commit above.