You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rework Import-CrmSolutionAsync to use the progress checking logic of Import-CrmSolution, and use $conn.ImportSolutionToCrmAsync call to get both async operation ID and import ID, rather than construct an async operation manually and not get the import ID
Write-Error"Async operation status check FAILED 5 times this could be due to a bug where the service returns a 401. Throwing lastException:";
2013
+
throw$conn.LastCrmException
2014
+
}
2015
+
Write-Verbose"Async operation status check FAILED this could be due to a bug where the service returns a 401. We'll allow up to 5 failures before aborting.";
Write-Error"Async operation status check FAILED 5 times this could be due to a bug where the service returns a 401. Throwing lastException:";
2039
+
throw$conn.LastCrmException
2040
+
}
2041
+
Write-Verbose"Async operation status check FAILED this could be due to a bug where the service returns a 401. We'll allow up to 5 failures before aborting.";
2046
2042
$transientFailureCount++;
2047
-
Write-Verbose"Import Job status check did not succeed: $($_.Exception)"
Write-Verbose"Executing for $($secondsSPentPolling.ToString("000"))/$MaxWaitTimeInSeconds seconds | Status: $($import.statuscode) ($statuscode)"
2056
-
}
2057
-
elseif($statuscode-eq31-or$statuscode-eq32 ){
2058
-
$isProcessing=$false
2059
-
throw"Status: $($import.statuscode) ($statuscode) | Operation has been either cancelled or has failed for Async Operation {$importId}.`n$($import.friendlymessage)"
Write-Verbose"SUCCESS: PublishChanges set, executing: Publish-CrmAllCustomization using the same connection."
2067
-
Publish-CrmAllCustomization-conn $conn
2068
-
return$import
2069
-
}
2070
-
else{
2071
-
Write-Verbose"SUCCESS: Import Complete, don't forget to publish customizations."
2072
-
return$import
2073
-
}
2074
-
break;
2075
-
}
2076
-
}
2077
-
2078
-
#User provided timeout and exit function with an error
2079
-
if($secondsSpentPolling-gt$MaxWaitTimeInSeconds){
2080
-
Write-Warning"Import-CrmSolutionAsync exited due to exceeding the maximum timeout of $MaxWaitTimeInSeconds. The import will continue in CRM async until it either succeeds or fails."
Write-Error"Import Job status check FAILED 5 times this could be due to a bug where the service returns a 401. Throwing lastException:";
2061
+
throw$conn.LastCrmException
2062
+
}
2063
+
Write-Verbose"Import Job status check FAILED this could be due to a bug where the service returns a 401. We'll allow up to 5 failures before aborting.";
#at this point we appear to have imported successfully
2083
-
return$asyncResponse;
2084
2139
} Catch {
2085
-
throw"AsyncOperation with ID: $importId has encountered an exception: $_"
2140
+
Write-Error"ImportJob with ID: $importId has encountered an exception: $_"
2141
+
} Finally{
2142
+
$ProcPercent= ([double](Coalesce $ProcPercent0))
2143
+
Write-Progress-Id 2-Completed -Activity "_"
2144
+
$timeSpentPolling.Stop()
2145
+
}
2146
+
#User provided timeout and exit function with an error
2147
+
if($timeSpentPolling.Elapsed-gt$timeout){
2148
+
throw"Import-CrmSolutionAsync halted due to exceeding the maximum timeout of $timeout."
2086
2149
}
2150
+
#detect a failure by a failure result OR the percent being less than 100%
2151
+
if(($importManifest.result.result-eq"failure") -or ($ProcPercent-lt100) -or$anyFailuresInImport) #Must look at %age instead of this result as the result is usually wrong!
2152
+
{
2153
+
Write-Verbose"Import result: failed - job with ID: $importId failed at $ProcPercent complete."
2154
+
throw$allErrorText
2155
+
}
2156
+
else
2157
+
{
2158
+
#at this point we appear to have imported successfully
2159
+
$managedsolution=$importManifest.Managed
2160
+
if($managedsolution-ne1)
2161
+
{
2162
+
if($PublishChanges){
2163
+
Write-Verbose"PublishChanges set, executing: Publish-CrmAllCustomization using the same connection."
0 commit comments