d365collaborative / d365fo.tools

Tools used for Dynamics 365 Finance and Operations
MIT License
250 stars 102 forks source link

Don't stop clearing tables if one is not present in the bacpac #490

Closed caleblanchard closed 3 years ago

caleblanchard commented 3 years ago

Right now, when using Clear-D365TableDataFromBacpac with a list of tables to clear, it will stop clearing tables from the bacpac once it hits a table that does not exist in the bacpac file. In my opinion, it should show a message that a table did not exist and it should keep going through the list.

https://github.com/d365collaborative/d365fo.tools/blob/6492559dba0fe489795fd3601c5a6faa7d8b272f/d365fo.tools/functions/clear-d365tabledatafrombacpac.ps1#L116

Splaxi commented 3 years ago

Come on @caleblanchard, are you spying on me? I hit the same issue with a customer, using the same command.

I'll see if I can implement some -ErrorAction SilentlyContinue support or similar. I actually want to support breaking execution on this, because a missing table could indicate other issues as well.

caleblanchard commented 3 years ago

Maybe a new parameter to stop on error? That way, the user can choose if they want it to stop or not?

Splaxi commented 3 years ago

Pull the lastest release in 20 minutes from now.

Get-Help Clear-D365TableDataFromBacpac -Examples

-------------------------- EXAMPLE 3 --------------------------

    PS C:\>Clear-D365TableDataFromBacpac -Path "C:\Temp\AxDB.bacpac" -TableName "CustomTableNameThatDoesNotExists","BAT
    CHJOBHISTORY" -OutputPath "C:\Temp\AXBD_Cleaned.bacpac" -ErrorAction SilentlyContinue

    This will remove the data from the BatchJobHistory table from inside the bacpac file.

    It uses "C:\Temp\AxDB.bacpac" as the Path for the bacpac file.
    It uses "CustomTableNameThatDoesNotExists","BATCHJOBHISTORY" as the TableName to delete data from.
    It respects the respects the ErrorAction "SilentlyContinue", and will continue removing tables from the bacpac file
    , even when some tables are missing.
    It uses "C:\Temp\AXBD_Cleaned.bacpac" as the OutputPath to where it will store the updated bacpac file.
caleblanchard commented 3 years ago

It does not appear to fix the issue. I ran it with -ErrorAction SilentlyContinue and it still stops processing the tables after it hits one that does not exist in the bacpac. Correct me if I am wrong, but I believe it is due to the return statement right after the Stop-PSFunction call that keeps it from processing the rest of the tables. https://github.com/d365collaborative/d365fo.tools/blob/f1ff2ea8a699f3c104bdd89fe480c02934f66558/d365fo.tools/functions/clear-d365tabledatafrombacpac.ps1#L124-L128

Splaxi commented 3 years ago

Yeah, I just discovered that.

Will push and update later today.

Sorry!

Splaxi commented 3 years ago

@caleblanchard Should be fixed in the latest version.

caleblanchard commented 3 years ago

Thank you! Just tested and it works now!