Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set-XrmClientTimeout not working #6

Closed
Nicer82 opened this issue Sep 20, 2022 · 3 comments
Closed

Set-XrmClientTimeout not working #6

Nicer82 opened this issue Sep 20, 2022 · 3 comments

Comments

@Nicer82
Copy link
Contributor

Nicer82 commented Sep 20, 2022

I am trying to change the default timeout of 00:02:00 to 00:10:00, however when I use Set-XrmClientTimeout, this doesn't seem to affect the timeout. Anyone knows how to solve this?

# Connection setup
$xrmClient = New-XrmClient -ConnectionString "AuthType=ClientSecret;url=$($TargetUrl);ClientId=$($TargetAppId);ClientSecret=$($TargetAppSecret)";
Set-XrmClientTimeout -DurationInMinutes 10;

# Get entity Id
$query = New-XrmQueryExpression -LogicalName "mserp_financeandoperationsentity";
$query.ColumnSet = [Microsoft.Xrm.Sdk.Query.ColumnSet]::new("mserp_physicalname");
$query.Criteria.AddCondition("mserp_physicalname", [Microsoft.Xrm.Sdk.Query.ConditionOperator]::Equal, "CustCustomerV3Entity")
$entity = (Get-XrmMultipleRecords -XrmClient $xrmClient -Query $query)[0];

# Refresh
try
{
    Write-Host "$(Get-Date): start refresh"
    $generatedEntity = [Microsoft.Xrm.Sdk.Entity]::new("mserp_financeandoperationsentity");
    $generatedEntity.Id = $entity.Id;
    $generatedEntity["mserp_refresh"] = $true;
    $xrmClient.Update($generatedEntity);
}
finally
{
    Write-Host "$(Get-Date): end refresh"
}

The above script gives me the output:

09/20/2022 15:35:05: start refresh
09/20/2022 15:37:05: end refresh
Exception calling "Update" with "1" argument(s): "The underlying connection was closed: A connection that was expected to be kept alive was closed by the server."

@Nicer82
Copy link
Contributor Author

Nicer82 commented Sep 20, 2022

Update: I fixed it by adding this line before calling New-XrmClient:

[Microsoft.Xrm.Tooling.Connector.CrmServiceClient]::MaxConnectionTimeout = [System.TimeSpan]::new(0,10,0);

Instead of using Set-XrmClientTimeout

@AymericM78
Copy link
Owner

AymericM78 commented Oct 2, 2022

Hello @Nicer82

Thanks for your contribution!

This is correct, Set-XrmTimeout was supported with WS-Trust auth type, now with OAuth it is deprecated.
I've tried your solution and it work great! :)
I add this parameter to New-XrmClient command -> e6646be .

Regarding your issue, I'm surprised about the update operation duration.
If I understand, you try to update 1 record with a simple attribute, this should not take more than 5s if other processes are triggered on server side. Maybe be you should have a look on plugin traces.

I notice that you are coding with .NET style instead of Powershell style.
You script should be :

# Connection setup
$xrmClient = New-XrmClient -ConnectionString "AuthType=ClientSecret;url=$($TargetUrl);ClientId=$($TargetAppId);ClientSecret=$($TargetAppSecret)";

# Get entity Id
$query = New-XrmQueryExpression -LogicalName "mserp_financeandoperationsentity" -Columns "mserp_physicalname" -TopCount 1;
$query = $query | Add-XrmQueryCondition -Field "mserp_physicalname" -Condition Equal -Values "CustCustomerV3Entity";
$results = Get-XrmMultipleRecords -XrmClient $xrmClient -Query $query;

$entity = $results | select -First 1;

# Refresh
Write-HostAndLog "Start refresh";

$generatedEntity = New-XrmEntity -LogicalName $entity.LogicalName -Id $entity.Id -Attributes @{
    "mserp_refresh" = $true
};
Update-XrmRecord -XrmClient $xrmClient -Record $generatedEntity;

Write-HostAndLog "End refresh";

Have a nice day!

@Nicer82
Copy link
Contributor Author

Nicer82 commented Oct 3, 2022

Yes, I know, I like the .net style coding more 😄.
Thx for the fix! The update I am doing implies a virtual entity refresh on the Dynamics 365 F&O side, standard msft stuff that takes time depending on the entity size, so not much I can do about it unfortunately...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants