4

Scenario: I have a template (say A), and having 50 page items already exist related to template type A.

Objective: Now have a requirement to add one more field for template A with default value '$name' into the standard value of this template.

Problem: Now if i'm going to create any new page item related to template A then it's working fine.

But for already existing 50 page item field added but field value is still showing '$name' instead of replace with page item's name.

5

You can use the powershell script below to update the values of your field. You have to replace Your field name with the field you need to change.

$dialog= Read-Variable -Parameters `
@{ Name = "media"; Title = "Path"; Root="/sitecore/"; Editor="item";Tab="General";},
 @{ Name = "contentType"; Title = "Content Type"; Root="/sitecore/templates"; Editor="item";Tab="General";} `
-Description "This script will edit field value " `
-Title "Field Value Update" -Width 500 -Height 500 `
-OkButtonName "Proceed" -CancelButtonName "Abort" 

if ($dialog -ne "ok")
 {   
   Exit
 }

cd $media.Paths.FullPath;$templateId = $contentType.ID

Write-Host "Process Starting";

Get-ChildItem -Recurse -Language * . |  ForEach-Object {
$this = $_
if($_.TemplateID -eq $templateId){     
if($_.Fields["Your field name"].Value -eq "$name")
  {
             $_.Editing.BeginEdit();
             $_['Your field name']=$_.Name;
             $_.Editing.EndEdit();
  }

 }    
}

Write-Host "Process Completed";
2

Standard Values will execute at the item creation. The Standard Values will not effect already existing items. You need to update values manually by writing custom script or you can use powershell module.

  • 3
    Although your intentions are correct - your statement is not. Standard values do not execute at item creation - I assume you mean that tokens in standard values are replaced at item creation ;) Your solution to use powershell is correct though. – Gatogordo Jan 1 '18 at 11:54
  • Is there any existing modules or PowerShell script to achieve this? – Pradeep Gupta Jan 1 '18 at 12:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.