Update of field value in a file within document library using powershell is not working

I have associated a custom content type to a document library and this content type as multiple fields.

The FieldXYZ termset from which this field is derived has 2 values ('Success' , 'Failed')

In my power shell script, I am updating a field FieldXYZ value for all documents in the root directory of the library

The powershell code for updating the field is as follows

$lists = $web.lists
foreach ($list in $lists) 
{
 if ($list.BaseType -eq [Microsoft.SharePoint.SPBaseType]::DocumentLibrary) 
 {
	write-host "Document Lib : " , $list.title
        SetFieldValuebyGUID($list.RootFolder)	
 }
}




Function SetFieldValuebyGUID($rootfolder)
	{ 
	  foreach($docfile in $rootfolder.Files)
	  {	
	    write-host $docfile.Properties["FieldXYZ"]
            $docfile.CheckOut()
	    $docfile.Properties["FieldXYZ"] = n5f52e7f-bb83-4c01-xxxxxxxxx
	    $docfile.Update();
	    $docfile.CheckIn('updated property GUID')
            write-host $docfile.Properties["FieldXYZ"]
         }
       }
     

Function SetFieldValuebyVal($rootfolder)
	{ 
	  foreach($docfile in $rootfolder.Files)
	  {	
	    write-host $docfile.Properties["FieldXYZ"]
            $docfile.CheckOut()
	    $docfile.Properties["FieldXYZ"] = "Success"
	    $docfile.Update();
	    $docfile.CheckIn('updated property GUID')
            write-host $docfile.Properties["FieldXYZ"]
         }
       }
     

The script is not updating the values of the field. 

Any ideas on how to resolve the issue would be appreciated.

Regards

Nate


  • Edited by Nate DFW Friday, July 24, 2015 9:00 PM update with termset
July 24th, 2015 8:57pm

Hi Nate,

    

From your code, the update could be either creating a new version or failing with some event trigger :

    $docfile.CheckOut()
   $docfile.Properties["FieldXYZ"] = "Success"
   $docfile.Update();
   $docfile.CheckIn('updated property GUID')

Take a look at some details about updating the document.

Update()
Updates the item in the database.
Updates the Modified and Modified by values.
Creates a new version

Systemupdate()
Updates the item in the database.
No changes in the Modified and Modified By fields.
No new version.
Triggers the item events.

Systemupdate(true)
Same as Systemupdate() and increments the item version.
Using SystemUpdate(false) is exactly the same as SystemUpdate()

UpdateOverwriteVersion()
Updates the item but does not create a new version.
Updates the Modified and Modified by values.

Note that :
You can also disable the triggering of events by using this.EventFiringEnabled = false;. Do your update and enable the events again with this.EventFiringEnabled = true;

Regards,

Rajesh

http://sharepointr.blogspot.sg/

Free Windows Admin Tool Kit Click here and download it now
July 25th, 2015 2:20am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics