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 :-
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