3

When we create an item in a Sitecore bucket folder using PowerShell Extensions like shown below:

New-Item -Path "$PathofBucketFolder" -Name $TitleofanItem -ItemType $TemplateofanItem

The item gets created in the bucket based on the rule we have set but it does not get focused. I mean after the item is created author has to go to the folder and see. Whereas in normal Sitecore way when we create the item in the bucket, the newly created item is navigated automatically by Sitecore in the content editor.

So my question is, is it not possible to navigate to the item when the item is created using PowerShell Extensions.

2
  • Assuming you're talking about the Content Editor, the Item won't get focused unless it's part of the standard Create Item dialog in the Shell. i.e. you have to select the parent and then an Insert Option. (Either Data Template or Branch Template). When is the code above firing, and how do you trigger it? Oct 5, 2017 at 13:56
  • Sergeant Sitecore Thanks for your response. We have implemented powershell script using command (i.e. in ribbon). Script will help to create item based on parameter passed i.e. tempalate , item title etc.. We have used sitecore powershell extension module for this. Let me know if you need any other details. Looking forward to hear from you. Thanks
    – cbrebel
    Oct 6, 2017 at 5:10

1 Answer 1

1

The solution I have found is to force the Bucket Syncronization. To Force the syncronization you have two option:

1) Define a custom Commandlet as defined here

2) Mixing C# with Powershell and create your sync function as descibed here

$Assem = (
    “Sitecore.Kernel, Version=10.0.0.0, Culture=neutral, PublicKeyToken=null” ,
    “Sitecore.Buckets, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null”
    )

$Source = @"
namespace Custom.Web.Powershell.Bucket{
    public class CustomBucketManager{
        public static void Sync(Sitecore.Data.Items.Item item)
        {
            using (new Sitecore.SecurityModel.SecurityDisabler())
            {
                Sitecore.Buckets.Managers.BucketManager.Sync(item);
            }
        }
        public static void Bucket(Sitecore.Data.Items.Item item)
        {
            using (new Sitecore.SecurityModel.SecurityDisabler())
            {
                Sitecore.Buckets.Managers.BucketManager.CreateBucket(item);
            }
        }
    }
}
"@
Add-Type -ReferencedAssemblies $Assem -TypeDefinition $Source -Language CSharp 


[Custom.Web.Powershell.Bucket.CustomBucketManager]::Sync($itemToBucket)

Your Answer

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

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