Showing posts with label sitecore10. Show all posts
Showing posts with label sitecore10. Show all posts

Thursday, September 25, 2025

Unlocking the Power of GraphQL in Sitecore: A Practical Guide to Queries, Mutations, and Fragments – Part 2

Hi Sitecore folks!,
Welcome back, fellow developers! In the previous post of our GraphQL series, we dived into the basics of querying for component data in Sitecore. If you missed it, be sure to check out [Unlocking the Power of GraphQL in Sitecore: A Guide to Useful Queries – Part 1].

In this second installment, we're going to take a deeper dive into some of the more advanced features of GraphQL: mutations, fragments, and some common queries. These powerful tools allow you to extend your GraphQL usage in Sitecore, making your development work more efficient and dynamic.

We'll walk through how to harness these features, explore real-life examples, and explain how they can streamline your content management workflows. Whether you’re new to GraphQL or a seasoned pro looking to sharpen your skills, this guide will provide you with the essentials to elevate your GraphQL game.

GraphQL Mutations: Modifying Data on the Server

GraphQL isn't just a tool for reading data—it also allows you to modify data via mutations. In Sitecore, mutations empower you to create, update, or delete items, templates, media, and more directly through GraphQL queries.

Unlike REST, which typically uses GET requests to retrieve data, GraphQL uses mutations to make changes to data. This distinction ensures that your data-modifying operations are organized and explicit, reducing the potential for confusion or errors.

Create Data with Mutations

Let's start by exploring a mutation for creating new items. This is useful when you're working with content that's frequently updated or needs to be programmatically generated. Here’s an example mutation for creating a new item in Sitecore:

mutation CreateItem { createItem( name: "Created MutationsItem" template: "{4330C04F-5CAA-4E93-A2B2-634900395E51}" parent: "{C081F940-3F38-4E10-8F43-B80AA63BC1BA}" language: "en" fields: [ { name: "title", value: "New Item Created with Mutations" } { name: "subtitle", value: "This is a new Sitecore item created using mutations." } ] ) { path id } }

This mutation will create a new item with a specific template, assign it to a parent item, and populate its fields (e.g., title and subtitle). The result will return the path and ID of the newly created item.

Update Data with Mutations

Next, let’s look at a mutation for updating an existing item. For example, if you need to update an item's title and subtitle, the mutation would look like this:

mutation UpdateItem { updateItem( path: "/sitecore/content/Home/MySampleProject/MutationsItem/CreatedMutationsItem" language: "en" version: 1 fields: [ { name: "title", value: "Updated Item Title" } { name: "subtitle", value: "Updated subtitle content for the item." } ] ) { title { value } subtitle { value } } }

This mutation targets a specific item and updates its fields with the new values. The query also returns the updated title and subtitle fields.

Delete Data with Mutations

Mutations aren't just for creating and updating—they’re also powerful for deleting content. Here's an example of a mutation that deletes an item:

mutation DeleteItem { deleteItem( path: "/sitecore/content/Home/MySampleProject/MutationsItem/CreatedMutationsItem" ) }

Once executed, the specified item is removed from Sitecore’s content tree.

Fragments: Modularizing Queries for Reusability

As your queries become more complex, you may notice a lot of repetition in your field selections. This is where fragments come into play. A fragment allows you to define a set of fields once and reuse them across multiple queries. This makes your queries more modular, cleaner, and easier to maintain.

In Sitecore, you might be dealing with nested content types, so creating reusable fragments for fields like title and subtitle is incredibly helpful.

Here's an example where we define two fragments: RelatedItems and SubRelatedItems. Each fragment specifies the fields we need for those content types:

fragment RelatedItems on RelatedItems { title { value } subtitle { value } } fragment SubRelatedItems on SubRelatedItems { title { value } subtitle { value } }

Now, you can use these fragments in your main query to fetch content in a cleaner, more efficient way:

query ContentCardQuery($datasource: String!) { datasource: item(path: $datasource, language: "en") { name newsItems: children( includeTemplateIDs: ["{B5D116DE-BFE8-4A06-A3FE-90C84320ECCB}"] ) { name ...RelatedItems } blogItems: children( includeTemplateIDs: ["{02CDBE64-254B-424B-90C3-E74FDBA02572}"] ) { name ...SubRelatedItems } } }

By using inline fragment spreads (...RelatedItems and ...SubRelatedItems), this query is now much cleaner and more maintainable. The fragments handle the repetitive fields for you, and you only need to call them where necessary.

Fetching and Organizing Data Efficiently

GraphQL shines when it comes to fetching specific data. You can retrieve exactly what you need, reducing unnecessary requests and optimizing your application. Here’s an example where we query multiple data sources under a parent item, and we fetch only the required fields for news and blog items:

query ContentCardQuery($datasource: String!) { datasource: item(path: $datasource, language: "en") { name newsItems: children( includeTemplateIDs: ["{B5D116DE-BFE8-4A06-A3FE-90C84320ECCB}"] ) { name ... on RelatedItems { title { value } subtitle { value } } } blogItems: children( includeTemplateIDs: ["{02CDBE64-254B-424B-90C3-E74FDBA02572}"] ) { name ... on SubRelatedItems { title { value } subtitle { value } } } } }

In this query, we use child item queries to pull news and blog items based on their specific templates. We then use fragments to ensure we fetch only the required fields for each item.

Conclusion: GraphQL’s Full Potential in Sitecore

GraphQL in Sitecore isn’t just a powerful tool for reading data; it offers a comprehensive way to manage and interact with content. By leveraging mutations for data creation, updates, and deletions, along with fragments for cleaner, reusable queries, you can optimize your Sitecore applications and workflows.

In this part of the series, we've covered the essential techniques for handling mutations and fragments, but we’re just scratching the surface. Stay tuned for Part 3, where we’ll dive into complex queries, variables, and directives—all the advanced tools you’ll need to become a GraphQL pro in Sitecore.

Until then, get hands-on with what we've covered, and experiment with mutations and fragments in your own projects. The more you practice, the easier it will get!

I hope you enjoy this Sitecore blog. Stay tuned for more Sitecore related articles.

Till that happy Sitecoring :)

Please leave your comments or share this article if it’s useful for you.

Wednesday, June 25, 2025

๐Ÿš€ Streamlining Sitecore Maintenance Post-Upgrade: How PowerShell Helped Us Fix Missing Templates and Flashes Items

Hi Sitecore folks! ๐Ÿ‘‹

Upgrading Sitecore is always an exciting step forward — more features, improved performance, and enhanced stability. But let’s be honest: it’s not always smooth sailing.

We recently upgraded from Sitecore 10.1 to 10.4, and while most things worked seamlessly, we hit a snag that many of you might also face post-upgrade — orphaned or missing templates, especially related to SXA Flash items.

In this blog, I’ll walk you through:

 ✅ What went wrong
 ✅ Why it mattered
 ✅ How we solved it using PowerShell (our superhero ๐Ÿฆธ‍♂️)
 ✅ And how you can do it too

Whether you’re maintaining a single Sitecore instance or overseeing 160+ SXA-based websites like we are — this one’s for you.

๐Ÿงจ The Issue: Missing Templates for Flash Items

After the upgrade, we noticed something odd in our SXA environments. In the Data folder, several “Flashes” items were still visible — but something wasn’t right:

  • We couldn’t interact with them.
  • Their templates were missing.
  • Deletion through the Content Editor? Not possible.

That’s when we turned to the old-school trick of visiting /sitecore/admin/dbbrowser.aspx, where we could manually select and delete these items. But here’s the thing—with 160+ websites across Dev, UAT, and Prod, manual cleanup just wasn’t an option.

๐Ÿ˜ซ Why Manual Fixes Just Don’t Scale

When you’re dealing with tens or hundreds of websites, manual steps become a maintenance nightmare. What if you miss one? What if someone deletes the wrong thing?

We needed:

  • ๐Ÿ’ก A repeatable, automated process
  • ⚡ A fast solution
  • ๐Ÿ”„ The ability to run across multiple environments without human error

And that’s where PowerShell stepped in and saved the day.

๐Ÿ’ป PowerShell to the Rescue

One of the most powerful tools in the Sitecore ecosystem is PowerShell Extensions (SPE). If you’re not using it yet — trust me, you’re missing out.

We wrote two scripts:

  1. ✅ One to identify Flash items with missing templates
  2. ❌ Another to delete them safely

๐Ÿ” Step 1: Identify Orphaned Flash Items

Here’s a sample PowerShell script that recursively searches for Flash items with missing templates:

# Define the template Name for the Settings item
$dataFolderTemplate = "DataFolder"

# List to hold matching flashes items
$matchingFlashes = @()

# Fast query to get all Settings items under /sitecore/content with the specified template ID
$dataItems = Get-Item -Path master: -Query "fast:/sitecore/content//*[@@templatename='$dataFolderTemplate']"

foreach ($dataItem in $dataItems) {
    
    # Check if the Settings item has a flashes item under it
    $flashPath = "$($dataItem.Paths.FullPath)/Flashes"
    $flashItem = Get-Item -Path $flashPath -ErrorAction SilentlyContinue

    # If flashes item exists and matches the target template ID
    if ($flashItem -ne $null) {
        #$flashItem | Set-ItemTemplate -Template $targetTemplateId
        #Publish-Item -Item $flashItem -Target "web" -Recurse
        
        $matchingFlashes += $flashItem
        #$flashItem | Remove-Item
        #Write-Host "  Found flashes: $($flashItem.Paths.FullPath)"
    }
    else{
        Write-Host " Not Found flashes: $($dataItem.Paths.FullPath)"
    }
}

# Output matched flashes items
#$matchingFlashes | Select-Object Name, TemplateName, @{Name="Path";Expression={$_.Paths.FullPath}}
$matchingFlashes | Show-ListView -Property Name, TemplateName, @{Name="Path";Expression={$_.Paths.FullPath}} -Title "Flash under Home"
# Show total count of matching $matchingFlashescts items
Write-Host ""
Write-Host "Total matching flashes items: $($matchingFlashes.Count)" -ForegroundColor Green
๐Ÿ“Œ This script outputs a clean list of problematic Flash items in your tree — 
great for auditing before deletion.

๐Ÿงน Step 2: Clean Up with a Deletion Script

Once verified, we ran the following PowerShell script to safely delete the Flash items:

# Define the template Name for the Settings item
$dataFolderTemplate = "DataFolder"

# List to hold matching flashes items
$matchingFlashes = @()

# Fast query to get all Settings items under /sitecore/content with the specified template ID
$dataItems = Get-Item -Path master: -Query "fast:/sitecore/content//*[@@templatename='$dataFolderTemplate']"

foreach ($dataItem in $dataItems) {
    
    # Check if the Settings item has a flashes item under it
    $flashPath = "$($dataItem.Paths.FullPath)/Flashes"
    $flashItem = Get-Item -Path $flashPath -ErrorAction SilentlyContinue

    # If flashes item exists and matches the target template ID
    if ($flashItem -ne $null) {
        #$flashItem | Set-ItemTemplate -Template $targetTemplateId
        #Publish-Item -Item $flashItem -Target "web" -Recurse
        
        $matchingFlashes += $flashItem
        $flashItem | Remove-Item
        #Write-Host "  Found flashes: $($flashItem.Paths.FullPath)"
    }
    else{
        Write-Host " Not Found flashes: $($dataItem.Paths.FullPath)"
    }
}

# Output matched flashes items
#$matchingFlashes | Select-Object Name, TemplateName, @{Name="Path";Expression={$_.Paths.FullPath}}
$matchingFlashes | Show-ListView -Property Name, TemplateName, @{Name="Path";Expression={$_.Paths.FullPath}} -Title "Flash under Home"
# Show total count of matching $matchingFlashescts items
Write-Host ""
Write-Host "Total matching flashes items: $($matchingFlashes.Count)" -ForegroundColor Green

๐ŸŽฏ This script saved us hours of manual work and helped ensure consistency across all environments.

๐ŸŽฏ Bonus: Target Specific Items If Needed

Need to delete a specific item? You can tweak the $sitecoreItemPath in the script:

$sitecoreItemPath = "/sitecore/content/your-specific-item-path"

๐Ÿ’ก This flexibility makes it easy to manage exceptions or troubleshoot individual issues without running global deletions.

๐Ÿง  Lessons Learned

  • Automate early. Don’t wait until the cleanup becomes overwhelming.
  • PowerShell is your best friend for large-scale Sitecore environments.
  • Always audit before deleting — especially post-upgrade when things can be unpredictable.
  • SXA upgrades may leave artifacts, so include this check in your post-upgrade checklist.

๐Ÿ™Œ Final Thoughts

If you’re upgrading Sitecore (or planning to), keep PowerShell in your toolkit. It’s not just a scripting language — it’s your automation Swiss Army knife ๐Ÿ”ง for Sitecore maintenance.

These scripts helped us clean up 160+ websites in minutes — not hours or days.

๐Ÿ—ฃ️ Over to You!

Have you faced a similar issue post-upgrade?
 Do you have other cleanup tips or automation tricks?
 Drop your thoughts in the comments — I’d love to learn from your experience!

๐Ÿ”— Script Reference:
 GitHub — DeleteFlashesItem.ps1

๐Ÿ“Œ Stay tuned for more Sitecore insights, real-world fixes, and automation guides.

Till then, happy Sitecoring! ๐Ÿ’™

Monday, April 21, 2025

Upgrading Sitecore from 10.1 to 10.4: Overcoming SXA Module Challenges

 

 Hello All,

Upgrading Sitecore from version 10.1 to 10.4 can be a significant step forward in leveraging the latest features and improvements. However, during our recent upgrade, we encountered an issue while upgrading the Sitecore Experience Accelerator (SXA) module. This post outlines the problem we faced and the solution that ultimately resolved the issue.

The Upgrade Process

We followed the official Sitecore SXA 10.4 upgrade guide, which can be found here. The guide provides a step-by-step approach to upgrading the SXA module, ensuring that all necessary components are updated correctly.

The Issue: Step 4 "Update Existing Content"

The problem arose during the fourth step of the upgrade process, "Update existing content." After upgrading Sitecore from 10.1.2 to 10.4, we attempted to upgrade the Sitecore SXA content by clicking the upgrade button. Unfortunately, this action resulted in an error.

Error Description:

  • A PowerShell pop-up appeared without any content.
  • Some sample screenshots:


Here below list of steps after click on upgrade :


Only one left apart from that all completed successfully.

Powershell pop up without any content:





Troubleshooting and Solution

Our team, along with Sitecore support, conducted extensive troubleshooting to identify the root cause of the issue. After a thorough investigation, we discovered that broken links at one of the website tenant levels were causing the problem.

Steps Taken to Resolve the Issue:

  1. Identify Broken Links: We meticulously checked the content for broken links within the affected tenant.
  2. Update Links: Once identified, we updated the broken links to ensure they pointed to valid content.
  3. Reattempt Upgrade: After fixing the broken links, we reattempted the upgrade process.

This approach successfully resolved the issue, allowing us to complete the SXA module upgrade without further errors.

Key Takeaways

  • Thorough Content Review: Before initiating the upgrade, ensure that all content, especially links, is intact and functional.
  • Collaborative Troubleshooting: Working closely with Sitecore support can expedite the resolution of complex issues.
  • Documentation: Always refer to the official upgrade guides and keep detailed records of any deviations or issues encountered during the process.

Conclusion

Upgrading Sitecore and its modules can present challenges, but with careful planning and thorough troubleshooting, these can be overcome. Our experience highlights the importance of detailed content review and collaboration with support teams to ensure a smooth upgrade process.

If you have any questions or need further assistance with your Sitecore upgrade, feel free to reach out!

I hope you enjoy this Sitecore blog. Stay tuned for more Sitecore related articles.

Till that happy Sitecoring :)

Please leave your comments or share this article if it’s useful for you.

 

 

Wednesday, November 13, 2024

Sitecore upgrade 10.1 to 10.4 - Part-1

 Hi All,

Upgrading from Sitecore 10.1 to Sitecore 10.4

I recently had the opportunity to upgrade Sitecore from version 10.1 to 10.4. During this process, I encountered several issues and challenges that I will outline in this series. My goal is to provide a detailed guide that others can leverage to facilitate their own upgrades, potentially helping them avoid similar pitfalls.

Steps for Upgrading to Sitecore 10.4:

  1. Prepare Your Solution:
    • Update the NuGet references to align with Sitecore 10.4.
    • Recompile your solution using the updated Sitecore DLLs.
    • Address any breaking changes that arise.
    • Prepare your deployment artifacts.
    • For further details, refer to the "Solution and Sitecore Updates" blog link.
  2. Backup and Update the Database:
  3. Install Sitecore 10.4 Instance:
    • Install a new instance of Sitecore 10.4.
    • Modify the ConnectionStrings.config file to connect the new Sitecore XP instance to the databases from the previous Sitecore XP version upgraded in the previous step.
  4. Deploy Solution Artifacts:
    • Deploy the Sitecore XP solution artifacts generated in step 1 to the new Sitecore XP installation.

By following these steps, you can ensure a smoother transition from Sitecore 10.1 to Sitecore 10.4. For additional guidance and detailed instructions, please refer to the series next blog post.

General Maintenance

After completing the upgrade and updating any Sitecore modules you use, and before starting to use Sitecore XP, you must:

  1. Clear the browser cache
  2. Republish your website to every publishing target
  3. Rebuild all content search indexes
  4. Rebuild the link databases

I hope you enjoy this Sitecore blog. Stay tuned for more Sitecore related articles.

Till that happy Sitecoring :)

Please leave your comments or share this article if it’s useful for you.