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

Enable users are not working #68

Open
Rameshdhamotheraswamy opened this issue Jul 12, 2023 · 17 comments
Open

Enable users are not working #68

Rameshdhamotheraswamy opened this issue Jul 12, 2023 · 17 comments

Comments

@Rameshdhamotheraswamy
Copy link

Hi
Thanks for the scripts for D365 F&O

I am using the script for enabling the users after the DB refresh the job is getting success but in the environment users are not enabled.

and the script is not working for EU region too.

@Splaxi
Copy link
Collaborator

Splaxi commented Jul 12, 2023

Could you share what payloads and OData endpoints that you are using?

For an user to be valid and useable inside D365FO - some basics has to be in place. If you have a working D365FO environment, with a specific user in it. You can get / export that user from the OData endpoint and compare it against the environment that doesn't work.

The EU region comment is a bit unclear to me. The d365fo.integrations will work against any D365FO instance, regardless region, as long as you can provide a valid OAuth 2.0 token (or ClientId / ClientSecret). If you can call the OData endpoint for the specific environment and get / export / fetch data - you know that the connection and token works. Then the issue could be the payload that you are sending to the OData endpoint.

@Rameshdhamotheraswamy
Copy link
Author

Hi

Thanks for the reply , i found the issue in the admin user username is empty so got the error and not enabled the users , after adding the name issue got resolved ..

for EU environment URL i am getting the below error when enabling the users

Get-D365ODataEntityData] Something went wrong while retrieving data from the OData endpoint for the entity: SystemUsers | The remote name could not be resolved: 'XXX.sandbox.operations.eu.dynamics.com'
WARNING: [03:25:57][Get-D365ODataEntityData] Stopping because of errors. | Something went wrong while retrieving data from the OData endpoint for the entity: SystemUsers

@Splaxi
Copy link
Collaborator

Splaxi commented Jul 14, 2023

And from the same machine you can actually reach the mentioned url from the error message?

The tools are not doing anything special, sp the error would indicate that your machine is able to resolve the uri.

Please try to copy the Uri from the error and paste it into your browser - from the same machine. Let me know what you find...

This is normally a DNS issue - way out of what we can assist with.

@Rameshdhamotheraswamy
Copy link
Author

Hi

i can able to access the URL only to the eu.dynamics it is not working

@Splaxi
Copy link
Collaborator

Splaxi commented Jul 20, 2023

Hi,

I just tested things out with the following code:

$token = Get-D365ODataToken -Tenant 000... -Url https://....test.sandbox.operations.eu.dynamics.com -ClientId 11111... -ClientSecret 'password....'
Get-D365ODataPublicEntity -EntityNameContains Sales -Token $token -SystemUrl https://....test.sandbox.operations.eu.dynamics.com -Url https://....test.sandbox.operations.eu.dynamics.com

And was able to get data back from the EU deployed Tier2.

If you are still struggling with the things, we could arrange a screensharing session and I could try to understand what you facing and see if I can unblock you.

@TrustCompact
Copy link

Hi

Thanks for the reply , i found the issue in the admin user username is empty so got the error and not enabled the users , after adding the name issue got resolved ..

for EU environment URL i am getting the below error when enabling the users

Get-D365ODataEntityData] Something went wrong while retrieving data from the OData endpoint for the entity: SystemUsers | The remote name could not be resolved: 'XXX.sandbox.operations.eu.dynamics.com' WARNING: [03:25:57][Get-D365ODataEntityData] Stopping because of errors. | Something went wrong while retrieving data from the OData endpoint for the entity: SystemUsers

Was there any other issue instead of the empty username in admin account? I am struggling with the same issue: I try to enable two users - code is running without errormessage, but users are not enabled in FO.

Running this operation with Postman (same clientID/-secret and so on) everything is working as intended, so I doubt that there are permission-problems.

Any help appreciated!

@Splaxi
Copy link
Collaborator

Splaxi commented May 14, 2024

Can you share your payload and commands that you're running.

If your payload in postman and powershell is 100% the same - it has to work. I'm keen to unblock you - so let me know if you need a hand.

@Splaxi
Copy link
Collaborator

Splaxi commented May 14, 2024

When things fail - could you try to type: $error in your powershell session?

image

@TrustCompact
Copy link

Can you share your payload and commands that you're running.

If your payload in postman and powershell is 100% the same - it has to work. I'm keen to unblock you - so let me know if you need a hand.

Took example from function-documentation, eg:

$payload = '{"Enabled":"true"}'
$updates = @([PSCustomObject]@{Key = "UserID='UserA'"; Payload = $payload})
$updates += [PSCustomObject]@{Key = "UserID='UserB'"; Payload = $payload}
Update-D365ODataEntityBatchMode -EntityName "SystemUsers" -Payload $($updates.ToArray()) -Token $token

Fehler beim Aufrufen der Methode, da [System.Management.Automation.PSCustomObject] keine Methode mit dem Namen
"ToArray" enthält.
In Zeile:1 Zeichen:70

  • ... hMode -EntityName "SystemUsers" -Payload $($updates.ToArray()) -Token ...
  •                                            ~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (ToArray:String) [], RuntimeException
    • FullyQualifiedErrorId : MethodNotFound

Update-D365ODataEntityBatchMode : Das Argument kann nicht an den Parameter "Payload" gebunden werden, da es NULL ist.
In Zeile:1 Zeichen:68

  • ... Mode -EntityName "SystemUsers" -Payload $($updates.ToArray()) -Token ...
  •                                         ~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidData: (:) [Update-D365ODataEntityBatchMode], ParameterBindingValidationException
    • FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Update-D365ODataEntityBatchMode

If .ToArray() is removed, no "direct" error occurs but nothing happens.
$Error returns above error and

Remove-Variable : Es kann keine Variable mit dem Namen "ODataSystemUrl" gefunden werden.
In C:\Program Files\WindowsPowerShell\Modules\d365fo.integrations\0.4.38\d365fo.integrations.psm1:1275 Zeichen:5

  • Remove-Variable -Name "ODataSystemUrl" -Scope "Script" -Force -Er ...
    
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : ObjectNotFound: (ODataSystemUrl:String) [Remove-Variable], ItemNotFoundException
    • FullyQualifiedErrorId : VariableNotFound,Microsoft.PowerShell.Commands.RemoveVariableCommand

@Splaxi
Copy link
Collaborator

Splaxi commented May 15, 2024

Please run $PsVersionTable

I would argue, that your array object isn't created correctly - based on the errors. Could you do a single update, in a loop - to unblock you? Then we can work on the batchmode in parallel...

@Splaxi
Copy link
Collaborator

Splaxi commented May 15, 2024

Please try this:

$payload = '{"Enabled":"true"}'
$updates = @([PSCustomObject]@{Key = "UserID='UserA'"; Payload = $payload})
$updates += [PSCustomObject]@{Key = "UserID='UserB'"; Payload = $payload}
Update-D365ODataEntityBatchMode -EntityName "SystemUsers" -Payload $updates -Token $token

or in a loop

$payload = '{"Enabled":"true"}'
$updates = @([PSCustomObject]@{Key = "UserID='UserA'"; Payload = $payload})
$updates += [PSCustomObject]@{Key = "UserID='UserB'"; Payload = $payload}
$updates | Foreach-Object {Update-D365ODataEntity -EntityName SystemUsers -Key $_.Key -Payload $_.Payload}

@TrustCompact
Copy link

$PsVersionTable

Name Value


PSVersion 5.1.17763.5696
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17763.5696
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

This is a default T1-DevBox from MS.

@TrustCompact
Copy link

Please try this:

$payload = '{"Enabled":"true"}'
$updates = @([PSCustomObject]@{Key = "UserID='UserA'"; Payload = $payload})
$updates += [PSCustomObject]@{Key = "UserID='UserB'"; Payload = $payload}
Update-D365ODataEntityBatchMode -EntityName "SystemUsers" -Payload $updates -Token $token

or in a loop

$payload = '{"Enabled":"true"}'
$updates = @([PSCustomObject]@{Key = "UserID='UserA'"; Payload = $payload})
$updates += [PSCustomObject]@{Key = "UserID='UserB'"; Payload = $payload}
$updates | Foreach-Object {Update-D365ODataEntity -EntityName SystemUsers -Key $_.Key -Payload $_.Payload}

The second version using loop and Update-D365ODataEntity works.
The "...BatchMode" does not. Maybe the PS-Version is the problem.

@TrustCompact
Copy link

Please try this:

$payload = '{"Enabled":"true"}'
$updates = @([PSCustomObject]@{Key = "UserID='UserA'"; Payload = $payload})
$updates += [PSCustomObject]@{Key = "UserID='UserB'"; Payload = $payload}
Update-D365ODataEntityBatchMode -EntityName "SystemUsers" -Payload $updates -Token $token

or in a loop

$payload = '{"Enabled":"true"}'
$updates = @([PSCustomObject]@{Key = "UserID='UserA'"; Payload = $payload})
$updates += [PSCustomObject]@{Key = "UserID='UserB'"; Payload = $payload}
$updates | Foreach-Object {Update-D365ODataEntity -EntityName SystemUsers -Key $_.Key -Payload $_.Payload}

The second version using loop and Update-D365ODataEntity works. The "...BatchMode" does not. Maybe the PS-Version is the problem.

Hm - no:
Version 7.4.2 fails but at lease with an error message:

Update-D365ODataEntityBatchMode: Cannot bind argument to parameter 'Payload' because it is null.
Remove-Variable: Cannot find a variable with the name 'ODataSystemUrl'.

InvalidOperation: Method invocation failed because [System.Management.Automation.PSCustomObject] does not contain a method named 'ToArray'.

Using "...-Payload $updates" instead of "...-Payload $updates.ToArray()" does not throw an error, but nothing happened on FO-side.

@Splaxi
Copy link
Collaborator

Splaxi commented May 16, 2024

This works - I just tested with one of my customers and their environments. A Tier1 - but still - it should work regardless, as long as the OData entity is available.

$payload = @{
    "Enabled" = "True"
} | ConvertTo-Json

$usersCol = New-Object System.Collections.Generic.List[System.Object]

$usersCol.Add( [PSCustomObject]@{Key = "UserID='abc'"; Payload = $payload })
$usersCol.Add( [PSCustomObject]@{Key = "UserID='def'"; Payload = $payload })

Update-D365ODataEntityBatchMode -EntityName SystemUsers -Payload $($usersCol.ToArray())

@TrustCompact
Copy link

This works - I just tested with one of my customers and their environments. A Tier1 - but still - it should work regardless, as long as the OData entity is available.

$payload = @{
    "Enabled" = "True"
} | ConvertTo-Json

$usersCol = New-Object System.Collections.Generic.List[System.Object]

$usersCol.Add( [PSCustomObject]@{Key = "UserID='abc'"; Payload = $payload })
$usersCol.Add( [PSCustomObject]@{Key = "UserID='def'"; Payload = $payload })

Update-D365ODataEntityBatchMode -EntityName SystemUsers -Payload $($usersCol.ToArray())

Nope - not working either. Same problem and behaviour as before. Even if I add the -token param ;)

@Splaxi
Copy link
Collaborator

Splaxi commented May 16, 2024

Then the next step is to do a offline / screensharing - where you can show me what you're actually doing. I noticed that your powershell session was in German, so our timezones should be compatible 🤞

Could you please verify - that you did a Add-D365ODataConfig - where you supply details for all parameters?

Add-D365ODataConfig -Name 'Temp' -Tenant -Url '' -SystemUrl '' -ClientId '' -ClientSecret '' -Force

Please note that the Url and SystemUrl, has to be the same value.

Next up is making the entire configuration, the active one.

Set-D365ActiveODataConfig -Name 'Temp'

Now you should be able to run my code, as this is the most common way to run the cmdlets, as the ODataConfig will fill out all default parameters, for all cmdlets calls. So no need for the -Token parm (unless you are an advanced user, but that is for another discussion)

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

3 participants