1

Does anyone know how to Update droptree field values through Powershell?

We have the bulk of items, which one of the field values as __Workflow state under workflow section[while we can see enable standard template]. we need to update as a state(__Workflow state) as empty for all the items. could you please suggest how we can write a query in Powershell.

$sourcepath="master:/sitecore/content/TestFolder";
$items= Get-ChildItem -path $sourcepath -Recurse

function Update-Item{

foreach($item in $items)
{
    if($item.TemplateId -eq "{292FD0AD-CE76-4867-B43B-A58FC8F36530}")       
    {
        Write-host  "Updating Item Name and AGE:" $item.ID "";
        $rawIds = [Sitecore.Data.Fields.ReferenceField]$item.Fields["__Workflow state"]
        $item.Editing.BeginEdit()
        
        $item.Editing.EndEdit()
    }   
}

$items = Update-Item
Close-Window

2 Answers 2

2

to make a field empty you can do it using:

 $item.Editing.BeginEdit()
 $item["__Workflow state"]=""
 $item.Editing.EndEdit()
1
  • Yeah its working. thanks. due to cache issue, its not reflected in browser. After checking incognito window. its showing perfectly.
    – PKH
    Feb 7 at 10:25
1

You can use the Reset-ItemField command to reset the workflow state to the default state. This is covered in Example 4 in the SPE book.

Reset-ItemField -Item $item -Name "__Workflow State" -IncludeStandardFields

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.