The Community is now in read-only mode to prepare for the launch of the new Flexera Community. During this time, you will be unable to register, log in, or access customer resources. Click here for more information.
We would like to restructure how the locations and categories are organized and would like to delete all existing location and category paths to reload new ones.
Is there a simple batch process that can do this since doing individually via the web interface would be too time consuming?
Example would be a stored database routine similar to deleting users in bulk with ComplianceUserRemoveBatch.
Apr 14, 2022 01:05 PM
Hi,
Please reach out to Support. They can help with providing the SQL. There are SQLs that have been used to perform cleanup for Cloud customers, which can be used for any OnPrem environments too.
Thanks!
Apr 14, 2022 04:55 PM
Here's an example of a SQL script that can be executed against the compliance database to delete all groups identified by the first query in this script:
-- This script will delete all enterprise groups identified by the following query:
SELECT GroupID
INTO #GroupsToDelete
FROM dbo.GroupEX_T
WHERE
GroupTypeID = 1 -- 1 = locations, 2 = corporate units, 3 = cost centers
AND BusinessView = 0 -- don't delete the root group
DECLARE db_cursor CURSOR FOR
SELECT GroupID from #GroupsToDelete ORDER BY GroupID
OPEN db_cursor
DECLARE @ID int
FETCH NEXT FROM db_cursor INTO @ID
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT @ID
EXEC dbo.GroupDeleteAndChildren @groupid = @ID
FETCH NEXT FROM db_cursor INTO @ID
END
CLOSE db_cursor
DEALLOCATE db_cursor
Apr 29, 2022 01:39 AM
Hi Chris,
Has this script been updated for changes in new FNMS versions? I'm getting
Invalid column name 'GroupExID'.
Procedure GroupDeleteAndChildren, Line 24 [Batch Start Line 0]
Invalid column name 'GroupExID'
I'm using FNMS 2022 R2
Maybe this procedure is now deprecated and we now have something new? Probably a column name changed by the message.
Regards,
Andrei
May 24, 2023 06:23 AM
I don't know of any changes, but it is possible the GroupDeleteAndChildren stored procedure does not work anymore. This stored procedure is not actually used by any functionality within FlexNet Manager Suite, so it could be deprecated.
Or is it possible that you have a customized stored procedure configured in your database? The "line 24" referenced in the error message seems a strange: I can't see how anything around line 24 in the stored procedure would obviously result in the error you are seeing.
If this procedure doesn't work anymore, new SQL script would be required to achieve this. I'm not sure if anybody here has a script to share.
May 24, 2023 09:28 PM
Hi,
Update: I was able to get a different script that doesn't use the "GroupDeleteAndChildren" stored procedure and works with FNMS 2022 R2. The only drawback is that it only works for costcenters since it removes all the references of costcenters in other tables. For anybody needing to delete something else like location or corporate unit, you can probably substitute costcenterid with locationid or corporate unitid in each of the update sections and will do just fine. Of course don't forget to test this on your test instance. I hope this will be useful for others looking for this in the future.
Regards,
Andrei
May 26, 2023 08:54 AM - edited May 26, 2023 08:56 AM
Hi Chris,
I used the script that I provided above for cost centers and substituted the cost center with category in each table that was referencing GroupEx for categories. I just wanted to send an update and let everyone later reading this case know this is not ideal and there were traces left in our DB. I opened a case with Flexera and was recommended to run the procedure below which fixed our issue.
EXEC PopulateInitialEnterpriseGroups_MT 1
However I now have another quiestion: knowing that this method cannot be used to remove categories, would it work for corporate units? We have over 1k corporate units and I need a script to remove everything and import clean data in a new format.
Regards,
Andrei
Jan 17, 2024 06:58 AM
Is there a way to do this in Flexera One?
deleting the entries in the WEB UI does not sound very smart...
Aug 10, 2023 02:10 AM
by the way, Idea submitted: Ability to delete more than one entry at a time in "IT Asset | Ideas (aha.io)
if anyone feels this to be of use, please vote 🙂
Aug 10, 2023 02:18 AM
Hi Kevin,
Basically, when deleting any node object below any of the 'Enterprise > Structure' node (Corporate Units, Locations, Cost Centers and Categories) from the FNMS UI, FNMS will recursively delete all child node objects of the parent object automatically.
Please note that default categories under "Hardware" and "Software" cannot be deleted.
As a 'best practice', you should create locations and categories in a structured hierachical way. As an example for locations, you can use "EMEA > Germany > Munich > Site A". This makes it easy to delete all child notes for "EMEA > Germany" or "EMEA > Germany > Munich" in a single step.
Aug 23, 2023 08:25 AM
Hi,
This does work if you have everything in the correct hierarchy. In our situation we had an import which did not go as planned 😄 and we ended up with ~2k lines on the root level 🙂
Aug 24, 2023 01:49 AM
Ladies,
feel free to try the script below.
/*
Script for deleting ALL 'Group' child objects for a certain Group Type in FNMS safely.
The script finds and deletes all direct child objects of the root object.
The trigger 'GroupExDelete' on the [GroupEx_MT] table makes sure that
- all additional child objects are deleted recursively
- All references to the deleted objects are removed.
There is an issue with this trigger, as it will not remove references in the [RoleRight]-Table.
If you are using an role that is scoped to a 'Group' (Location, Cost Center ...), this
scoping MUST be removed first.
If not, you will get a 'REFERENCE constraint "FK_RoleRight_Scope_MT"' error message.
*/
/* @GroupTypeID: 1=Locations, 2=Departments, 3=Cost Center, 4=Category - see table [GroupType] */
DECLARE @GroupTypeID INT
SET @GroupTypeID = 1 -- adapt this to the object type where you would like child objects to be removed
; WITH
cteRootObjectGroupID(GroupID) AS
(
/* Returns the 'GroupID' value for the root object for object type '@GroupTypeID' */
SELECT ge.GroupID
FROM [GroupEx] ge
WHERE
ge.GroupTypeID = @GroupTypeID
AND ge.BusinessView = 1
),
cteFirstLevelChildren(GroupID) AS
(
/* Returns the 'GroupID' values for all direct children of the root group object */
SELECT
TargetID AS [GroupID]
FROM [MemberEx] m
JOIN cteRootObjectGroupID rog on rog.GroupID = m.GroupID
)
DELETE FROM [GroupEx_T]
WHERE
GroupID IN (SELECT GroupID FROM cteFirstLevelChildren)
As usual, doing a backup of your FNMSCompliance database before deleting data is a good idea 😁.
Jan 17, 2024 06:07 PM
Hi Erwin,
Thank you for this script. It seems to be working however I still have my main problem. I always get a foreign key constraint error when trying to delete drom GroupEx_T and I need to go and manually set the BusinessUnitID to null in many other tables (ComplianceUser_MT, ComplianceComputer_MT, Asset_MT) probably others as well, however since it takes half a day to remove from one I'm still working on this. I thought the flag is going to take care of it and deleting from GroupEx_T will take care or all other tables related to GroupEx_MT however that is not happening. Am I getting something wrong? So far I'm doing this in test and I can afford to play with it, however setting BusinessUnitID to null in all those tables is super time consuming.
Regards,
Andrei
Feb 07, 2024 05:52 AM
Hi Andrei,
There is a trigger named 'GroupExDelete' on the [GroupEx_MT] table. This trigger makes sure that all references to objects in tables like [ComplianceUser_MT], [ComplianceComputer_MT], [Asset_MT] ... are removed in case objects are deleted from the [GroupEx_T].
This trigger sets all references from the GroupEx_T] table in the 'LocationID', 'BusinessUnitID', 'CostCenterID' and 'CategoryID' target columns are set to NULL for the object(s) that are deleted.
Take a look at the source code of this trigger please in case you want to batch delete references manually.
Feb 26, 2024 07:51 AM