3

We have written one rule for bucket items and it gets triggered when an bucket item is created or item is saved. for creating an bucket item we use below code

$updatedItem=New-Item -Path "$parentPath" -Name $Title -ItemType $Template

Now when the item is created , the rule is triggered which is expected. After that I want to trigger the same rule again when the item's fields get updated. I have used below code to update the item fields

$updatedItem.Editing.BeginEdit()
$updatedItem.Title=$NewsTitle      
$updatedItem.DateTime=$NewsDate
$updatedItem.Editing.EndEdit() 

Now these fields get updated silently in sitecore but the save event is not fired and because of that the rule is not triggered. I also used below code to explicitly trigger the event but that too did not work.

$updatedItem.Editing.EndEdit($false,$true)

Is there any way where I can trigger the rule from power shell script or trigger the save event.

1

One approach would be to trigger the Bucket Sync command after the edits are completed.

Example: The following syncs the bucketed items after the careers import finished and before publishing. This could take a while if there is a large number of items.

Write-Verbose "Syncing jobs buckets."   
$careersBucketItem = Get-Item -Path $careersPSPath
[Sitecore.Buckets.Managers.BucketManager]::Sync($careersBucketItem)
  • Hi Michael, Thanks for your reply. That did not solve the issue either, after syncing the bucket it still not trigger the save event. So what I would like to do is once item is created based on the date I want to change the location of the newly created item in the bucket using below line ruleContext.ResolvedPath = date.ToString(format, CultureInfo.InvariantCulture); So could you tell me how can this be done using powershell script. I used this line in the script but it did not work. [Sitecore.Buckets.Rules.Bucketing.BucketRuleContext]::ResolvedPath($articleDate) – Kapil Naker Oct 10 '17 at 4:39
  • Hi Michael, with your bucket sync code and few of code tweaks we were able to achieve what was expected. Thank you. However, as you mentioned it takes time as we have huge amount of data. I would like to use the BucketRuleContext's resolve path method but not sure how to do it in powershell script. ruleContext.ResolvedPath = date.ToString(format, CultureInfo.InvariantCulture); If you could help would be great – Kapil Naker Oct 10 '17 at 7:33

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.