0

I'm working with Sitecore 9.2 , And I need to create a custom button inside custom ribbon when click on button open dialog so the content author can select date and then i will do my business function after that

  • first i created the ribbon
  • then i created the button
  • i created the command class which will contain the powershell code and my business function

the problem that the powershell script didn't executed , i need to know how to write powershell inside C# class and why my code didn't executed

public override void Execute(CommandContext context){
using (ScriptSession scriptSession = ScriptSessionManager.NewSession("Default", true)){ 
var command = "$result = Read-Variable -Parameters ` @{ Name=\"from\"; Value=[System.DateTime]::Now.AddDays(-5); Title=\"Start Date\"; Tooltip=\"Date since when you want the report to run\"; Editor=\"date time\"}` -Description \"This Dialog shows less editors, it doesn't need tabs as there is less of the edited variables\" `" +
" -Title \"Initialise various variable types (without tabs)\" -Width 500 -Height 480 -OkButtonName \"Proceed\" -CancelButtonName \"Abort\"  ";
List<object> results;
results = scriptSession.ExecuteScriptPart(command, false);
}
}

i found this error in the SPE log

Exception: System.InvalidOperationException Message: Non interactive session cannot perform an interactive operation requested by the 'Read-Variable' command.

5
  • 2
    you can add a button to the ribbon without C# code. wouldn't it be enough for you? doc.sitecorepowershell.com/modules/integration-points/… Commented Oct 27, 2020 at 12:35
  • 3
    Definitely overdoing things here. There are integration points that allow you to tap into the various features of the Content Editor with only items and PowerShell. Commented Oct 27, 2020 at 12:47
  • 1
    Seems kind of counter-intuitive to go the effort of creating a button in C# and then not just writing the code in C#.... Commented Oct 27, 2020 at 15:10
  • Thank you @TamásTárnok i will try this option, if it's worked it enough for sure Commented Oct 27, 2020 at 18:55
  • thank you @MichaelWest i will try powershell integration Commented Oct 27, 2020 at 18:57

1 Answer 1

0

As per suggestion from @Tamás Tárnok and @Michael West ,it's easy way to create ribbon button using Powershell without any C# code

this Document is helpful powershell integration Points

and this link step by step to create ribbon button using powershell

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.