I need to find all templates that use a defined field type.
What is the best way to do it ?
Sitecore Stack Exchange is a question and answer site for developers and end users of the Sitecore CMS and multichannel marketing software. It only takes a minute to sign up.
Sign up to join this communityI need to find all templates that use a defined field type.
What is the best way to do it ?
As field types are not linked with item's ID
you cannot use Link Database for that.
You could iterate through all fields in PowerShell and find those with particular field type
Open SQL Management studio Execute something like that
SELECT TOP 1000
[ItemId]
,[FieldId]
,[Value]
,[Created]
,[Updated]
FROM [sc_sitecore_master].[dbo].[SharedFields]
WHERE FieldId = '{AB162CC0-DC80-4ABF-8871-998EE5D7BA32}' AND Value = 'MY FIELD NAME'
where
MY FIELD NAME
is a file type name{AB162CC0-DC80-4ABF-8871-998EE5D7BA32}
in this case is an id of Type field (Sitecore field), notice that query is executed agains SharedFields
table not Items
– Alan Płócieniak
Feb 20 '17 at 12:29
I used a variation of Balaji's answer to search for data templates that contain a particular field type (in this case "link"), rather than for content with the field type. This also pops up the results in SPE's nice data grid for printing as HTML or exporting to a spreadsheet.
Get-ChildItem -Path "/sitecore/templates" -Recurse | Where-Object {$_.Fields["{AB162CC0-DC80-4ABF-8871-998EE5D7BA32}"] -like "link"} | Show-ListView -Property FullPath, Id
If you have powershell extension, you can try
Get-ChildItem -Path "/sitecore/content" -Recurse | Where-Object {$_.Fields["{AB162CC0-DC80-4ABF-8871-998EE5D7BA32}"] -like "Text"}
I ended up doing this to find templates utilizing a specific field type
$startPath = "master:/sitecore/templates/Features"
Write-Host "Search started $(Get-Date -format 'u')"
$list = [System.Collections.ArrayList]@()
$itemsToProcess = Get-ChildItem $startPath -Recurse
Write-Host "Items found: $($itemsToProcess.Count)"
if($itemsToProcess -ne $null) {
$itemsToProcess | ForEach-Object {
$match = 0;
if($_.Type -eq "General Link") {
$info = [PSCustomObject]@{
"ID"=$_.ID
"Path"=$_.Paths.FullPath
"Language"=$_.Language
"TemplateName"=$_.TemplateName
"FieldName"=$_.Name
"FieldType"=$_.Type
}
[void]$list.Add($info)
}
}
}
Write-Host "Search ended $(Get-Date -format 'u')"
Write-Host "Items found: $($list.Count)"
$list | Show-ListView
Replace $startPath with your path and replace the field type with what you need to find. In my example I was looking for a "General Link"