0

i am trying to update 2 hyperlink fields (internal names=Hlink1,Hlink2) in powershell,but i am getting "Value does not fall under expected range" error once it hits $Item.SystemUpdate(), but if i remove the $spqQuery.ViewFields it will work fine with out any problem. (below is the code sample)

 $spList = $spWeb.Lists[$List.Title]
                $spqQuery = New-Object Microsoft.SharePoint.SPQuery 
                $spqQuery.Query= "<Query><Where> 
                                <Geq> 
                                    <FieldRef Name='ID'/>
                                    <Value Type='Counter'>1
                                         </Value> 
                                             </Geq> 
                                                </Where></Query>"                           
                $spqQuery.ViewFields = "<ViewFields><FieldRef Name='Title'/><FieldRef Name='Hlink1'/><FieldRef Name='Hlink2'/></ViewFields>"
                $spqQuery.ViewFieldsOnly = $true
                if($spqQuery -ne $null)
                {
                $splListItems = $spList.GetItems($spqQuery) 
                } 

                Write-Host $splListItems.Count

            foreach($Item in $splListItems)
            {
                $UrlField= new-object Microsoft.SharePoint.SPFieldUrlValue($Item["Hlink1"])
                $UrlField.Url=$UrlField.Url
                $UrlField.Description = $UrlField.Url.ToString()
                $Item[$Field.InternalName]= $UrlField.Description
                $Item["Title"]= "abcd"
                $Item.SystemUpdate()
            }
  • in above code i cannot see the $true variable you can try with replacing $true to true. at $spqQuery.ViewFieldsOnly = $true – Sunil Sahu Jul 17 '18 at 6:23
0

Make sure the field used in $Item[$Field.InternalName] is included in ViewFields definition, if this field is not included in the ViewFields, it will throw Value not fall under expected range.

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.