Let's say, you create a new record in Dimension Value table. Then you select this new dimension value somewhere in the application, let's say, in General Journal line. This is the first time you are using this dimension value, so new record in Dimension Set Entry is created. Next, you change your mind and decide not to use this dimension value. You delete this dimension vaue from journal line. Next, you want to delete this record from Dimension Value table. But you get an error "This Dimension Value has been used in posted or budget entries. You cannot delete it". ](*,)
Of course, it's never been used in any posted or budget entries... The function CheckIfDimValueUsed in table 349 (OnDelete trigger) simply checks if record with the same Dimension Value ID exists in Dimension Set Entry table.
CheckIfDimValueUsed() : Boolean
DimSetEntry.SETCURRENTKEY("Dimension Value ID");
DimSetEntry.SETRANGE("Dimension Value ID","Dimension Value ID");
EXIT(NOT DimSetEntry.ISEMPTY);
The problem is when you delete dim value from general journal line, the record in Dimension Set Entry table is not deleted. New dimension set ID is being assigned to the journal line, but old one is not deleted. It stuck forever, even if it is never in use again. So, you are not able to delete dimension value record even if it is not used at all.
Is it supposed to work like that, or I am missing something?
Comments
If it were used ever, it does not have to be created.
It's the design.
Prevoius design of OnDelete trigger in table 349 was much more consistent. It checked supplemental dimension tables only, and nothing else. That makes much more sense. I understand, with current design which uses Dimension Set Entry table it should be different approach to check if dim value have been used, but technically it is not impossible. However, MS obviously chose the easiest way at this moment. Not saying that the error message does not reflect a reality now and leads to confusion.
To see if the dimension is used you just have to see if any of the dimension set ID's with the dimension value exist on any records.
If you can rely on the tablerelation the test loop isn't complicated, but can of course be slow. Make a filterstring containing all the dimension set IDs where the dimension value is used. loop all records in Field table with filter on RelationTableNo=Dimension Set Entry, for each Field record open a recordref and fieldref and filter with the dimension set ID filterstrin, test if a record exist.
I would also delete the dimension sets that includes the dimension value.
After Reading a bit more about "Dimension Set Tree Node" I decided not to touch "Dimension Set Entry" and I have just deleted the Dimension Value. I figured that in worst case scenario, Flowfields in "Dimenstion Set Entry" will not be calculated and table will have more entries indeed but these are not accesible anyway. Theoretically, Dimension Value can be restored with proper Code. I have even tried to delete dimension Value but for already used "Dimension Set ID". Except for missing Name complete "Dimensions Set" was shown from Document. Posting wasn't not possible though. I didn't want to mess with the tree, because it looked like it can be a tricky thing.