d365collaborative / d365fo.tools

Tools used for Dynamics 365 Finance and Operations
MIT License
246 stars 101 forks source link

Invoke-D365DbSyncModule fails if there are no BaseSyncElements #515

Closed FH-Inway closed 3 years ago

FH-Inway commented 3 years ago

Calling Invoke-D365DbSyncModule for a module that contains only table extensions fails with the following error message. This seems to be caused by line 145 in the script Invoke-D365DbSyncModule.ps1

SyncList = $allModelSyncElements.BaseSyncElements;

Would be nice if Invoke-D365DbSyncModule would support this scenario or at least provide a meaningful error message.

Invoke-D365DbSyncModule : Cannot bind argument to parameter 'SyncList' because 
it is an empty array.
At 
C:\DynamicsSDK\VSOAgent\_work\_temp\326cd1de-6157-4c3e-b4f5-fc39f0035783.ps1:4 
char:1
+ Invoke-D365DbSyncModule -Module "MyModule"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Invoke-D365DbSyncModule], Para 
   meterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyArrayNotAll 
   owed,Invoke-D365DbSyncModule

##[error]PowerShell exited with code '1'.
Splaxi commented 3 years ago

Could you try to edit the file and load the module again?

I'm not the master mind behind this, so I need some help making sure we don't break stuff, while we add support for your scenario.

Would a switch parameter, changed the behavior be feasible?

Splaxi commented 3 years ago

Please read this, if you plan on editing the file locally.

https://github.com/d365collaborative/d365fo.tools/wiki/Load-individual-files-or-dot-source-the-files

Commands.ps1 is the file you should edit 😁

FH-Inway commented 3 years ago

The error is actually caused in line 160 of Invoke-D365DbSyncMocule where the Invoke-D365DbSyncPartial function is called. The reason for the error is that this function declares the SyncList parameter as mandatory, see commit f16ca1163a077d0bf9a2df09d3ad1237690dd5a4 I tried running the module sync with SyncList not being mandatory and it seems to work. Also tested with an empty module that had no objects (so both SyncList and SyncExtensionsList are empty). It still ran the script, though it probably would make sense to add a check to the script and if both parameters are empty, abort it with a warning message. The only other script that calls Invoke-D365DbSyncPartial is Invoke-D365ProcessModule, which does the same thing as Invoke-D365DbSyncModule when it comes to database synchronisation. So I don't think making the parameter optional would break anything. Let me know if I can go ahead with the change.

Splaxi commented 3 years ago

Please come up with a PR and let's work together to see if we can make it happen.

Splaxi commented 3 years ago

0.6.53 should contain the fix.