0

I want to create an interactive dialog using PowerShell script.

I have multiple sites under the same Tenant if I select any site node in field 1, then field 2 root node should be changed to that site's Data folder. Then the user can select any item under the Data folder.

Scenario:

Tenant A

  • SiteA
    • SiteA/Data/Form Folder
  • SiteB
    • SiteB/Data/Form Folder

If user select SiteA in the Field 1, then Field 2 should show SiteA/Data/Form Folder as its starting node.

Edit:

$dialog = Read-Variable -Parameters `
    @{ Name = "language"; Title = "Select Language"; Source="DataSource=/sitecore/system/languages"; Editor="droplist"},
    @{ Name = "siteNode"; Title = "Select Site"; Source="DataSource=/sitecore/content/Sitecore902&DatabaseName=master&IncludeTemplatesForDisplay=Site"; editor="droplist"} `
    -Description "This module is used to import Data." `
    -Width 400 -Height 200 `
    -Title "Import Utility" `
    -OkButtonName "Select" `
    -CancelButtonName "Cancel"

if ($dialog -ne "ok") 
{
    Exit
}

$dialog1 = Read-Variable -Parameters `
    @{ Name = "itemPath"; Title = "Select Location"; Root=$siteNode.Paths.FullPath + "/Data/POIs"; Editor="item"} `
    -Description "This module is used to import Data." `
    -Width 400 -Height 200 `
    -Title "Import Utility" `
    -OkButtonName "Import" `
    -CancelButtonName "Cancel"

if ($dialog1 -ne "ok") 
{
    Exit
}

In here, I am using two Read-Variable. As you can see the value of siteNode is being used in itemPath. I want all the selections in one dialog box, and the functionality should remain the same. Right now, if I add itemPath to the $dialog, it is not working as expected.

Thanks for the help.

  • 1
    Have you checked out the examples under the Getting Started module? There is an example "Kitchen Sink" script that shows how to work with Read-Variable. – Michael West Jun 6 at 14:19
  • Yes, I checked that example, I also created a workaround, but I need all the fields in the same dialog box. Please have a look at the edit I made to the question. – PSS Jun 7 at 8:32
  • If I understand correctly, you want to set the second field from the value selected in the first, within a single dialogue. I'm not aware of any way to do this, or even of any events that you could use within a dialogue to build the functionality yourself. – James Walford Jun 24 at 11:51
  • @JamesWalford yes initially I was looking for the same functionality as you stated. But I couldn't able to find anything on that. So, I opted to go with 2 dialog boxes as you can see in the Edit part of the question. Thanks. – PSS Jun 24 at 11:56
1

You have issues with syntax in your second dialogue, essentially you weren't concatenating the string like you thought you were. This should work.

$dialog1 = Read-Variable -Parameters `
    @{ Name = "itemPath"; Title = "Select Location"; Root="$($siteNode.Paths.FullPath)/Data/POIs"; Editor="item"} `
    -Description "This module is used to import Data." `
    -Width 400 -Height 200 `
    -Title "Import Utility" `
    -OkButtonName "Import" `
    -CancelButtonName "Cancel"

Let's build up what's happening here in stages:

Root is expecting a string, so we start with Root="" You want to embed a variable in this string, so you add your $sitenode

Root="$siteNode.Paths.FullPath"

But PowerShell is then interpreting the object properties as a literal string. It calls object.ToString() on the $siteNode variable itself. The actual content of the string Root is now: "Sitecore.Data.Items.Item.Paths.FullPath"

So you need to wrap anything you need evaluated (properties, methods) in $()

Root="$($siteNode.Paths.FullPath)"

Now the $siteNode properties/methods are evaluated instead of being embedded into the string as string literals - the Root string is the full path of your siteNode item.

But you want to specify a specific path beneath the siteNode path, so you add your relative path directly to the string:

Root="$($siteNode.Paths.FullPath)/Data/POIs"

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.