Skip to content

Commit

Permalink
fixed Test-CrmViewPerformance
Browse files Browse the repository at this point in the history
  • Loading branch information
kenakamu committed Dec 25, 2015
1 parent f41bedb commit c754b67
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions Microsoft.Xrm.Data.PowerShell/Microsoft.Xrm.Data.PowerShell.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -7753,7 +7753,6 @@ function Test-CrmViewPerformance{

$conn = VerifyCrmConnectionParam $conn;

# Define query related values
if($IsUserView)
{
$logicalName = "userquery"
Expand All @@ -7774,7 +7773,7 @@ function Test-CrmViewPerformance{
elseif($viewName -ne "")
{
$views = Get-CrmRecords -conn $conn -EntityLogicalName $logicalName -FilterAttribute name -FilterOperator eq -FilterValue $viewName -Fields $fields
if($views.CrmRecords.Count -eq 0)
if($views.CrmRecords.Count -eq 0)
{
return
}
Expand All @@ -7787,51 +7786,51 @@ function Test-CrmViewPerformance{
# if the view has ownerid, then its User Defined View
if($View.ownerid -ne $null)
{
if($RunAs -ne $null)
if($RunAsViewOwner)
{
Set-CrmConnectionCallerId -conn $conn -CallerId $RunAs
Set-CrmConnectionCallerId -conn $conn -CallerId $view.ownerid_property.Value.Id
}
elseif($RunAs -ne $null)
{
Set-CrmConnectionCallerId -conn $conn -CallerId $RunAs
}
else
{
Set-CrmConnectionCallerId -conn $conn -CallerId (Get-MyCrmUserId -conn $conn)
}

# Get all records by using viewname
# Get all records by using Fetch
Test-XrmTimerStart
$records = Get-CrmRecordsByFetch -conn $conn -Fetch $View.fetchxml -AllRows -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
$perf = Test-XrmTimerStop
$owner = "System"
$owner = $View.ownerid
$totalCount = $records.Count
}
else
{
if($RunAsViewOwner)
{
Set-CrmConnectionCallerId -conn $conn -CallerId $view.ownerid_property.Value.Id
}
elseif($RunAs -ne $null)
{
if($RunAs -ne $null)
{
Set-CrmConnectionCallerId -conn $conn -CallerId $RunAs
Set-CrmConnectionCallerId -conn $conn -CallerId $RunAs
}
else
{
Set-CrmConnectionCallerId -conn $conn -CallerId (Get-MyCrmUserId -conn $conn)
}

# Get all records by using viewname
# Get all records by using Fetch
Test-XrmTimerStart
$records = Get-CrmRecordsByFetch -conn $conn -Fetch $View.fetchxml -AllRows -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
$perf = Test-XrmTimerStop
$owner = $View.ownerid
$owner = "System"
$totalCount = $records.Count
}

# Create result set
$psobj = New-Object -TypeName System.Management.Automation.PSObject

Add-Member -InputObject $psobj -MemberType NoteProperty -Name "ViewName" -Value $View.name
Add-Member -InputObject $psobj -MemberType NoteProperty -Name "Entity" -Value $View.returnedtypecode
Add-Member -InputObject $psobj -MemberType NoteProperty -Name "FetchXml" -Value $View.fetchxml
Add-Member -InputObject $psobj -MemberType NoteProperty -Name "Entity" -Value $View.returnedtypecode
Add-Member -InputObject $psobj -MemberType NoteProperty -Name "Columns" -Value ([xml]$view.layoutxml).grid.row.cell.Count
Add-Member -InputObject $psobj -MemberType NoteProperty -Name "LayoutXml" -Value $view.layoutxml
Add-Member -InputObject $psobj -MemberType NoteProperty -Name "TotalRecords" -Value $totalCount
Expand Down

0 comments on commit c754b67

Please sign in to comment.