Skip to content

Instantly share code, notes, and snippets.

@agehlot
agehlot / powershell-page-components.ps1
Created July 20, 2023 12:00
Get page wise component list from Sitecore tree
<#
This script will Find all components / renderings added on an item in Sitetree.
Goes through all child items and finds the renderings for that item
#>
$allRendering = Get-ChildItem -Path "master:\layout\Renderings" -Recurse |
Where-Object { $_.TemplateName -like "*rendering*" } |
Select-Object Name, ID, TemplateName |
Sort-Object -Property Name
$rootPath = 'master:/sitecore/content/NOV Com/Home'
@agehlot
agehlot / powershell-unused-rendering.ps1
Last active July 20, 2023 11:58
Sitecore PowerShell script to get list of un used components
<#
.SYNOPSIS
Lists the components (renderings) which are not or no longer linked to a page.
.NOTES
Ramon Bruelisauer (original code frame)
Manuel Fischer (adjustements und changes for using it with renderings)
#>
<##
@agehlot
agehlot / cdp-sql-sum-order-total
Created May 4, 2023 06:34
CDP SQL query that selects customers where the sum of all their order totals is greater than 100
select g.meta_ref as guest_ref
from (select meta_guest_ref
from partners_sandbox.orders
where upper(partners_sandbox.orders.type) = upper('STANDARD')
group by meta_guest_ref
having SUM(partners_sandbox.orders.core_price) > 100.0) as o
inner join partners_sandbox.guests as g
on o.meta_guest_ref = g.meta_ref
group by g.meta_ref
@agehlot
agehlot / cdp-sql-sum-session-data
Last active May 4, 2023 06:33
This SQL can be used to aggregate fields covering sessions and events
select g.meta_ref as guest_ref
from (select meta_guest_ref
from sandbox_tenant_06.sessions as s
inner join (select * from sandbox_tenant_06.events where upper(sandbox_tenant_06.events.type) = upper('POINTSCOLLECTED')) as e
on s.meta_ref = e.meta_session_ref
group by s.meta_guest_ref
having SUM(cast(e.ext['points'] as double)) > 20) as j
inner join sandbox_tenant_06.guests as g
on j.meta_guest_ref = g.meta_ref
group by g.meta_ref
@agehlot
agehlot / cdp-decision-model-offers.xml
Created November 9, 2022 15:55
Sitecore decision model sample to calculate offers on the basis of email address and search event.
<definitions xmlns="http://www.omg.org/spec/DMN/20151101/dmn.xsd" xmlns:biodi="http://bpmn.io/schema/dmn/biodi/1.0" xmlns:camunda="http://camunda.org/schema/1.0/dmn" namespace="http://camunda.org/schema/1.0/dmn" name="definitions" id="definitions"><decision id="a9ec2391-a481-4311-873d-f128c794c58e" name="heroImg"><extensionElements><biodi:bounds x="10" y="10" width="200" height="73.3"/><biodi:edge source="adcc5777-dbb3-46d6-9289-90c408a140ee"/></extensionElements><informationRequirement><requiredDecision href="#adcc5777-dbb3-46d6-9289-90c408a140ee"/></informationRequirement><decisionTable hitPolicy="FIRST"><input id="string65da1e2a-8111-444e-a2d1-bbf66ba1fc6a" label="Persona" camunda:inputVariable=""><inputExpression typeRef="string"><text>persona</text></inputExpression></input><output id="stringa13b850c-f2be-4201-8c8c-3075dc0afe38" label="Img" name="heroImg" typeRef="string"/><rule id="heroImg_0"><inputEntry id="input6b38cbc1-9142-410e-a812-785ed03b747f"><text><![CDATA["family-kids"]]></text></inputEntry><o
@agehlot
agehlot / sonarqube-command.cmd
Created November 9, 2022 14:34
CLI command to execute sonar qube execution
Sitecore Cloud
=============================================================================================
SonarScanner.MSBuild.exe begin /o:"app-one" /k:"sitecore-001" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.login="9d25b5f7c3efdb14a07da6f580932c94f00403aa"
MsBuild.exe Sitecore-Review.sln /t:Rebuild
SonarScanner.MSBuild.exe end /d:sonar.login="9d25b5f7c3efdb14a07da6f580932c94f00403aa"insert into NotificationQueue(UniqueId, ItemPublishQueueUniqueId, UserId, DealInLikedCategory, IsProcessed, NotificationMessageUniqueId, DateCreated, DateChanged)values(NEWID(), NEWID(), '5bc1ce12-f365-46c2-ba8f-d01ba43e66c1', 1, 0, '8a90352e-1409-4810-80e1-007262f3b7f5', '2008-11-11', '2008-11-11')
@agehlot
agehlot / sitecore-delete-contacts-interactions.sql
Last active October 2, 2022 15:14
These are the SQL scripts that can be used to delete all contacts and their interactions and make the xdb clean.
USE [yourdatabaseprefix.Collection.ShardX]
GO
DELETE FROM [xdb_collection].ContactIdentifiers
Delete from [xdb_collection].ContactFacets
Delete from [xdb_collection].InteractionFacets
Delete from [xdb_collection].Interactions
Delete from [xdb_collection].Contacts
@agehlot
agehlot / azure-apim-policy-allow-only-get-post.xml
Created September 30, 2022 11:46
Disable other methods except get and post in the inbound request
<on-error>
<base />
<choose>
<when condition="@(context.Request.Method != "GET" && context.Request.Method != "POST")">
<return-response>
<set-status code="405" reason="Method not allowed" />
<set-body>@{
return new JObject(
new JProperty("status", "HTTP 405"),
new JProperty("message", "Method not allowed")
// Logs of the last 100 calls
// Get the logs of the most recent 100 calls in the last 24 hours.
ApiManagementGatewayLogs
| where Url != 'https://fortune-prod-apim.azure-api.net/health/check'
| top 100 by TimeGenerated desc
// Get the logs of the requests that contains text fashion in the url.
ApiManagementGatewayLogs
| where Url contains "Fashion"
| top 500 by TimeGenerated desc
@agehlot
agehlot / reset-base-template.ps1
Last active September 24, 2022 08:33
Sitecore PowerShell script to recursively reset the base template of all items under given path.
Get-ChildItem "/sitecore/templates/Feature/Fortune" -Recurse |% {
$currentTemplate = $_
$templateIds |% {
$currentTemplate."__Base Template" = $currentTemplate."__Base Template" -Replace "$($.ID)|", ""
$currentTemplate."__Base Template" = $currentTemplate."__Base Template" -Replace "$($.ID)", ""
}
}
$templateIds |% {
$deletingTemplate = $_
Get-ChildItem "/sitecore/content" -Recurse | ? { $_.TemplateName -eq $deletingTemplate.Name } | Remove-Item