Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 12 Next »

Reparenting of resources is currently not supported in the GoMeddo UI and requires some additional work when done otherwise. Ideally it would be best to export existing Reservations, delete the entire Resources and Resource Types tree, rebuild it from scratch and then import the Reservations to the right parent. However ever if for any reason that is not possible, you can try this workaround. This needs to be carefully checked before executed, we don’t offer any support or guarantees that this will work.

Before Reparenting

  1. Disable any custom logic (Process Builder/ Lightning Flows/ Apex) on the Resource object

  2. Go to Custom Settings

  3. Click Manage next to System Setting

  4. Click New

  5. Create a setting as follows:

    1. Name: Disable ResourceType

    2. Boolean Value: TRUE

  6. This will disable the Resource Type trigger in GoMeddo.

Reparenting Resources

You may now either manually reparent your Resources. Alternatively, you can run this script with the correct Resource Type and Resource names. This will adjust the type tree and move the resource to their new parent.

The changes that are being made make to the Resource Type tree and Resource tree need to match (A child of a Resource needs to have a Resource Type that is a child of the parent Resource’s Resource’s Type). Normally the Resource and Resource Type triggers validate this, but as those have been disabled during this process, you could create an invalid configuration. Reenabling the trigger after this process will not correct any incorrect parent relationships or other errors introduced.

String moveType = '<The type of the resources that should be move>';
String newParentName = '<The new parent resource for these resources>';
B25__Resource_Type__c toMoveType = [SELECT Id, Parent__c FROM B25__Resource_Type__c WHERE Name = :moveType];
B25__Resource__c newParent = [SELECT Id, B25__Resource_Type__c FROM B25__Resource__c WHERE Name = :newParentName];
Id oldParentType = newParent.B25__Resource_Type__c;

// Set the type of the new parent so that it has the type that the records we want to move have as parent right now
newParent.B25__Resource_Type__c = toMoveType.Parent__c;
Database.update(newParent);

// Move the resource type tree
toMoveType.Parent__c = oldParentType;
Database.update(toMoveType);

// Reparent the resources
List<B25__Resource__c> resourcesToMove = [SELECT Id FROM B25__Resource__c WHERE B25__Resource_Type__r.Name = :moveType];
for (B25__Resource__c resource : resourcesToMove) {
    resource.Parent__c = newParent.Id;
}
Database.update(resourcesToMove);

// Set the type back to the old value
newParent.B25__Resource_Type__c = oldParentType;
Database.update(newParent);

After Reparenting

  1. Remove the Custom Setting, or set the boolean value to false for Disable ResourceType to reenable the Resource Type triggers

  2. This process might have broken the materialised path in the org run, so please run Fix Materialized Path

  3. Re-enable any custom logic on the resource

  • No labels