Posts

Creating Email Template In Content Hub Programmatically

Image
Hello everyone, In this blog we will see, how we can create mail template programatically in Sitecore Content Hub. So let's quickly try to see the code and we will understand it afterwwards. using System.Collections; using System.Collections.Generic; using System.Globalization; using System.Linq; using Stylelabs.M.Sdk; using Stylelabs.M.Sdk.Models.Notifications; using Stylelabs.M.Sdk.Contracts.Notifications; using Stylelabs.M.Sdk.Contracts.Base; using Stylelabs.M.Sdk.Contracts.Content; using Stylelabs.M.Base.Querying; using Stylelabs.M.Base.Querying.Filters; CultureInfo culture = CultureInfo.GetCultureInfo("en-US"); MClient.Logger.Info($"SS - Creating Email Template"); IMailTemplate template = await MClient.EntityFactory.CreateAsync(Constants.MailTemplate.DefinitionName) as IMailTemplate; template.Name = "MailNotificationReject"; template.SetSubject(culture, "SS Mail Notification Reject"); template.SetBody(culture, "Email...

Running Database Clean Up Task Manually After Sitecore Upgrade in Docker

Hello everyone, In this blog we will see how we can run database clean up task manaully using Sitecore CLI and why it is important especially during upgrade. Recently, we were working on Sitecore upgrade project from 10.1 to 10.3. Our solution was based on Docker setup. If you go through Sitecore Upgrade guide for container, you will find that Sitecore provide mssql-upgrade docker image which takes care of upgrading the SQL schema and tables required for the required Sitecore version to function properly.But if you closely observe during sql upgrade, you will see Sitecore modules are not updated during the process. Sitecore documentation guide provide information how we can upgrade different Sitecore module which is used in the solution. In our solution, we were using Sitecore PowerShell and Sitecore SXA module.Also in Sitecore 10.3, Sitecore is providing this module as Item As Resource( .dat files ) instead Sitecore Items in the package. So whenever we are upgrading, we need to remo...

PowerShell Script to update Alt tag missing for Images

Hello everyone. I am back with another powershell script that can be very useful if you want to update alt tag missing for all images in sitecore.We all know, how important is alt tag from SEO perspective and that's why, this powershell script can come very handy when we have lot of missing alt tag for images. Below is the powershell script for your reference.The script is pretty simple to understand. $rootPathOfImages = "/sitecore/media library/Project/" $testMode = $false $secondsToWaitOnLimitError = 60 $successCount = 0 $errorCount = 0 $errorList = "" $date = Get-Date $formattedDate =$date.tostring('dd-mmm-yyyy-hhmmss') # List of template ids to exclude from processing $excludedTemplateIds = @( "{FE5DD826-48C6-436D-B87A-7C4210C7413B}", #media folder "{0603F166-35B8-469F-8123-E8D87BEDC171}", #pdf "{16692733-9A61-45E6-B0D4-4C0C06F8DD3C}", #doc "{7BB0411F-50CD-4C21-AD8F-1FCDE7C3AFFE}", #...

Creating Custom Component in Content Hub using External Component

Image
Hello everyone, In this blog, we will see how we can add an custom component in Content Hub. We will create a component which will display all related assets based on loaded Asset title. Creating custom component depends on utilizing External Component.So we will follow below steps to achieve the same. We will be using Knockout JS for the implementation. Step1 : Adding External Page Component to Asset Detail Page Step2 : Code Logic implementing Related Asset Component Step 1 Go To Manage Page --> Search Pages --> Search Asset Details. Select Any row and click on add component basically the + symbol. In above screenshot, just click the plus symbol below Related Asset component.A popup will come up. Search for External keywork in search bar and click the result which comes up.Another popup will come and we will give our component a name and enable the visisble checkbox as shown below and click Add.The component will be added to layout. Once the component is added, just c...

Extract Metadata Properties from File and Update Asset fields in Content Hub through Script While Asset Creation

Image
Hello everyone, In this blog, we will see how we can update custom field values define in M.Asset Entity definition, when we add any asset. Let's see the custom field in M.Asset Entity Definition. Here we assume, we are aware, how to add custom fields to M.Asset Schema. Let's get started. Below are the steps that are required to accomplish this process. Step 1: Creating a Metadata Processing Script : This script will be having logic to update the fields. Step 2: Creating an Enitity by uploading a new Asset. Step 3: Verifying the updated values in the Entity newly created. let's start with creating a new script in Content Hub. Click on Manage page section as highlighted below in screenshot in blue. Then search for Scripts in search box. Click on the scripts result and you will be navigated to Scripts page On Scripts click on Add Script button to add a new script. On click a Dialog box will open just give a appropriate script name and choose action as Metad...

Identity Server Throwing Error while upgrading Sitecore Docker Image from 101 to 103

Image
Hello everyone, in this blog we will see one issue regarding Identity Server throwing 404 eventhough the container is up and running.In my case, this is happening when i am trying to Upgrade the Sitecore image from 10.1 to 10.3.We will see the steps, to troubleshoot the issue. Error Encountered : exec's CreateProcess() failed [error=container d40d350982e92e2df17722f254128af302877e86748d58e79fb6a5f2f303139d encountered an error during hcs::System::CreateProcess: failure in a Windows system call: The system cannot find the file specified. (0x2) [Event Detail: Provider: 00000000-0000-0000-0000-000000000000] [Event Detail: Provider: 00000000-0000-0000-0000-000000000000] [Event Detail: onecore\vm\compute\management\orchestration\vmhostedcontainer\processmanagement.cpp(173)\vmcomputeagent.exe!00007FF70737A1DB: (caller: 00007FF70732E19A) Exception(32) tid(3dc) 80070002 The system cannot find the file specified. CallContext:[\Bridge_ProcessMessage\VmHostedContainer_ExecuteProcess] ...

Reading AppRoute Data In Sitecore NEXT JS

Image
Hello everyone, in this blog we will see, how we can read route data from layout service. So let's start. By Default, we have default field in Sitecore for all default page template.That is PageTitle. We can add our own custom fields also.This fields are exposed using Layout Service.Let's see how we can read it. Sitecore structure Layout Service Front End Code to Read Route Data import {Field,useSitecoreContext,Text } from '@sitecore-jss/sitecore-jss-nextjs'; type CustomRouteTypeContext = { route: { fields: { pageTitle: Field<string>; }; }; }; const ReadApprouteData = () => { const {sitecoreContext: {route: { fields },},} = useSitecoreContext<CustomRouteTypeContext>(); console.log(fields); return( <div> <Text field={fields.pageTitle} /> </div>) }; export default ReadApprouteData If you see, we are using the useSitecoreContext hook to retrieve the route da...

More GraphQL Query Example In Sitecore JSS

Image
Hello everyone. In this blog we will see more example of writing GraphQL queries. This is continue part of my previous blog which you can find here So let's start without wasting any extra time. Below is the Sitecore structure which we will be using in our case. Let me give you an overview. We are having going to read children of Social Links folder. There are links item created from two different template. One is Social Link and another one is Footer Link. This is just for example purpose. Social Link template has one Image field named as logo. Below is the screenshot for your reference. Reading Children of Item passed as query parameter in GraphQL If you see above query, we are passing datasource and language as Paramter. Then we are calling children which is responsible for getting all Sitecore items under result object.We are just showing the template name and item name from the result Reading Children of of Item passed as Query in GraphQL with template id filter If y...

Reading Sitecore GraphQL data in Next JS

Image
Hello everyone, in this blog we will try to learn how we can fetch the data from Sitecore using GraphQL and build the component in Next JS application. We will utilize the Tiles component which was build in my last blog regarding GraphQL. The blog link is available Here This is just an example as same component can be developed using Layout service also. Lets see the code for the front end and try to see learn what each code function do. import React from "react"; import { GetStaticComponentProps, useComponentProps, JSS_MODE_DISCONNECTED, GraphQLRequestClient, } from '@sitecore-jss/sitecore-jss-nextjs'; import { StyleguideComponentProps } from 'lib/component-props'; import config from 'temp/config'; type ListItem = { Image : { src : string; alt : string; } TileLink : { target : string; text : string; url : string; } Title : { value : string; } id : string; } const Tiles = (props:...

Custom Scriban Object processor in SXA

Image
Hello everyone, In this blog, we will learn one more important concepts in Sitecore SXA and i.e. Custom Scriban object. As scriban was introduced in Sitecore 9.3 SXA, more developer started using Scriban while creating rendering variants. By default Sitecore provide a number of built-in Scriban Objects which you find on the Sitecore document site Link . Still there are time, where we need to create our own custom Scriban objects and we will see this here, how we can implement it. Let's take a use case: Reading Dictionary directly inside Scriban template. For this we don't have any built-in object and we will implement it using custom Scriban Object. Steps for creating Custom Scriban Object Creating custom Scriban processor inheriting from IGenerateScribanContextProcessor Registering the Processor under generateScribanContext pipeline So lets see the code without wasting any more time. Step 1: Create a Custom Scriban Processor ( GetDictionary ). Inherit the class from Add...