3

I am working on Sitecore PowerShell Extensions 5.0.0.42513 with Sitecore 9.0. I have started facing issue as Get-ItemReferrer : Object reference not set to an instance of an object

Also shown below in screenshot :-

enter image description here

Complete stack trace is as follows :-

Get-ItemReferrer : Object reference not set to an instance of an object.
At C:\inetpub\wwwroot\sc901.local\temp\tmp7605.ps1:3 char:19
+ ... ringItems = Get-ItemReferrer -Id "{C674D9DF-B5EA-4F3B-8871-F80B2F214F ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [Get-ItemReferrer], NullReferenceException
+ FullyQualifiedErrorId : System.NullReferenceException,Cognifide.PowerShell.Commandlets.Data.GetItemReferrerCommand

Point to be noticed here is that this script was working fine on Sitecore 8 with Sitecore PowerShell Extensions-4.7.2 for Sitecore 8.

Now I have upgraded my local instance to Sitecore 9.0.1 and Sitecore PowerShell Extensions 5.0.0.42513 and now getting this error.

I have also gone through with the link SPE Object reference not set to an instance of an object

I have also tried to execute few basic commands (which are working fine) to be sure that setup is not corrupted.

Not sure if Get-ItemReferrer has been deprecated, if yes then what is the alternative for this.

Any pointer in this regard is highly appreciated.

Update 1 :- Below is the script for reference.

$workflowStateID = Get-Item -Path master: -ID "{C674D9DF-B5EA-4F3B-8871-F80B2F214F28}"
$referringItems = Get-ItemReferrer -Item $workflowStateID | Where-Object { $_.__Updated -gt [datetime]::Now.AddDays(-30) -and $_.__Created -gt [datetime]::Now.AddDays(-30)}

#EmptyArray
$listofWorkflowItems = @()

#$listofWorkflowItems

#Skip System Items
Foreach($item in $referringItems) { 

    $itemPaths = $item.Paths.FullPath
    if($item.Paths.FullPath.contains('/sitecore/content/abc-website'))
    {
        $rendering = $item | Get-Rendering

        $addInList = New-Object System.Object
        $addInList | Add-Member -type NoteProperty -name ID -Value $item.ID
        $addInList | Add-Member -type NoteProperty -name Path -Value $item.FullPath
        $addInList | Add-Member -type NoteProperty -name ItemCreateDate -Value $item.Created

        if($item.'__Never publish' -eq 1)
        {
            $addInList | Add-Member -type NoteProperty -name Publishable -Value 'True'
        }
        else{
            $addInList | Add-Member -type NoteProperty -name Publishable -Value 'False'
        }       

        $workflowdetailList = Get-ItemWorkflowEvent -Id $item.ID | Where-Object { $_.NewState -eq '{C674D9DF-B5EA-4F3B-8871-F80B2F214F28}' } | Sort-Object -Property Date -Descending

        Foreach($workflow in $workflowdetailList){
                $addInList | Add-Member -type NoteProperty -name WorkflowApprover -Value $workflow.User
                $addInList | Add-Member -type NoteProperty -name ApprovedDate -Value $workflow.Date
                break
        }

        if($rendering){
            $addInList | Add-Member -type NoteProperty -name URL -Value $item.FullPath.Replace("/sitecore/content/abc-website/home","https://abc.com") 
        }

        $listofWorkflowItems += $addInList
    }
}
$listofWorkflowItems | Show-ListView
5
  • Can you please share the script you are executing and also make sure that you have rebuild the link database and that the item id you are searching exists Commented Nov 22, 2019 at 18:53
  • Can you rebuild your link database? Does the issue continue? Commented Nov 22, 2019 at 19:22
  • @HishaamNamooya I have updated the question with the script. Kindly refer. I have checked the item id and it exists. I am facing issue in rebuilding link database. Below is the error stack trace :- Object reference not set to an instance of an object. [NullReferenceException: Object reference not set to an instance of an object.] Sitecore.Shell.Applications.Dialogs.RebuildLinkDatabase.RebuildLinkDatabaseForm.CheckStatus() +201 [TargetInvocationException: Exception has been thrown by the target of an invocation.]
    – SumitK
    Commented Nov 23, 2019 at 16:37
  • @MichaelWest I tried rebuilding link database and I am getting error on this step. Object reference not set to an instance of an object. [NullReferenceException: Object reference not set to an instance of an object.] Sitecore.Shell.Applications.Dialogs.RebuildLinkDatabase.RebuildLinkDatabaseForm.CheckStatus() +201 [TargetInvocationException: Exception has been thrown by the target of an invocation.]
    – SumitK
    Commented Nov 23, 2019 at 16:39
  • 1
    Then I suspect the issue has more to do with that than it does SPE. Commented Nov 23, 2019 at 18:19

1 Answer 1

-1

I was getting the "Object reference not set to an instance of an object" error for Update-ItemReferrer. I was able to resolve it by rebuilding the links database. I'm using Sitecore 10.2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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