0

The official SPE docs does not provide the available option parameters for every field type on the Read-Variable command, so I’m curious if it is possible to block of dates before a set date on a date field datepicker?

3
  • What do you mean by the block of dates? Can you please elaborate more? Aug 31 at 12:15
  • Block like for example dates before 8/24/2022 are not selectable
    – Lala
    Aug 31 at 13:43
  • 1
    As of SPE 6.3 there is no OOTB way to add attributes to the date picker which would influence the min/max selectable dates. As proposed by @SumitBhatia you could go the validation message approach by prompting the user to make corrections. Aug 31 at 13:58

1 Answer 1

1

The Sitecore document for Read-Variable provides these parameters to use.

  • Name - the name of the PowerShell variable - without the $ sign
  • Value - the initial value of the variable - if the variable have not been created prior to launching the dialog - this will be its value unless the user changes it. if Value is not specified - the existing variable name will be used.
  • Title - The title for the variable shown above the variable editor.
  • Tooltip - The hint describing the parameter further - if the -ShowHints parameter is provided this value will show between the Variable Title and the variable editor.
  • Editor - If the default editor selected does not provide the functionality expected - you can specify this value to customize it (see examples)
  • Tab - if this parameter is specified on any Variable the multi-tab dialog will be used instead of a simple one. Provide the tab name on which the variable editor should appear.

And for the field types, it has the following description.

  • Root - for some Item selecting editors you can provide this to limit the selection to only part of the tree
  • Source - for some Item selecting editors you can provide this to parametrize the item selection editor. (Refer to examples for some sample usages)
  • Lines - for String variable you can select this parameter if you want to present the user with the multiline editor. The for this parameter is the number of lines that the editor will be configured with.
  • Domain - for user and role selectors you can limit the users & roles presented to only the domain - specified)

Read more - https://doc.sitecorepowershell.com/appendix/common/read-variable#parameters-less-than-object-greater-than

For the date field, you can use the parameters like this.

$item = Get-Item master:\content\home
$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"}

To perform a date validation this solution will work for you.

$result = Read-Variable -Parameters `
    @{ Name = "dateTimeSelector"; 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 a compare" `
    -Title "Date Compare" -Width 500 -Height 480 `
    -OkButtonName "Proceed" -CancelButtonName "Abort" `
    -Validator {
        $selectedValue = $variables.dateTimeSelector.Value
        $compareDate  = Get-Date 2022-8-24
  
        if ($selectedValue -lt $compareDate) 
        {
            $variables.dateTimeSelector.Error ="Date before Aug 24 2022 are not selectable"
        }
}

So if you will execute this, it will show the validation message like this.

enter image description here

For more about the validation, please refer to this link.

https://www.sitecorespark.com/blog/2020/7/readvariable-validation-with-sitecore-powershell-extensions

Hope this makes sense.

2
  • But I cannot configure it in such a way that dates before august 24 2022 are not selectable, for example?
    – Lala
    Aug 31 at 13:45
  • @Lala Updated my answer. Aug 31 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.