Creating items into multiple locations using SPE

When we work with Multisite solution where in the same Sitecore instance we have different sites for different regions/country, or when we go with several micro sites configuration based on Master site, there are scenarios when we have to create new item(s) based on specific template(s) on all the sites that has been created as part of the instance.

There is absolutely no issue when we are dealing with few sites and pages, but how about when we have more sites? and what if we have to create more than one item under each site?

As a solution we can go to each site node and create the expected items manually, but this approach is going to take good amount of time to complete the full process.

Sitecore Powershell Extensions-1

Solution:

Instead we can leverage Sitecore PowerShell Extensions (SPE) to perform this activity, this is much fast and one of the best approach to complete this operation.

For example– If we want to add two items based on two different templates on the same Sitecore Instance, you can use the following script for that and this will get the job done.

Get-Item master: -Query "/sitecore/content//*[@@templatename='Home Page']" | ForEach-Object {
$newpath= $_.FullPath
$item = New-Item $newpath -Name TestArticle -type "/sitecore/templates/User Defined/Sandbox/Article"
$item = New-Item $newpath -Name FAQ -type "/sitecore/templates/User Defined/Sandbox/FAQ"
}

Sitecore Powershell Extensions

In the above example what i have done is:

  1. Querying all the home nodes under /sitecore/content – based on “Home Page” template.
  2. Taking each home item as context and running “New-Item” SPE command to create an item based on template passed.
  3. As we are running two commands, two items will get created under each site.

Thanks to Michael West and Adam Najmanowicz for this great module.

Hope this is helpful and can save someone’s time who is trying to do something similar.

Happy learning ­čÖé

References:

  1. https://doc.sitecorepowershell.com/
  2. https://sitecorepowershell.com/

 

Advertisements

Versioned-Unversioned and Shared fields in Sitecore

This blog contains information about items, more importantly languages of items, versions of items in languages, and sharing the values of individual item in different supported languages and numbered versions.

This post is focused on explaining the differences between Versioned,Unversioned and shared fields in Sitecore.

Versioning of an item is controlled in three ways:

  1. Versioned fields
  2. Unversioned fields and
  3. Shared fields

VersionedFields

Versioned fields:

By default all the fields are versioned, which means the the field value will be different across different numberd versions and different language versions as well,
example of numbered version-  title/description and etc, or any such field whose field will be different across different languages/versions.

Unversioned fields:

There are certain fields whose value is same for all the numbered versions for a specific language, such as “Country Name”, “Employee Name” and etc, if we want to have such configuration, we should make that field as “Unversioned” in template definition.
When this(“Unversioned”) ┬ácheckbox is selected, the field has the same value for every numbered version within a language, but may have different values between supported languages.

Shared fields:

When the field value doesn’t change across languages and number versions, we should mark that field as shared, shared field value will be common across supported languages and versions.
When the Shared property is set, changes to the field value in any language or numbered version of the item will be reflected in all the other language versions and numbered versions.Example- “Id” or some unique identifier which will be commons across languages and versions.

I hope this helps someone in understanding the core concepts and versioned fields.

Please let me know your feedback, or your thoughts on the same.

Happy learning ­čÖé