Forum:  Designer

Thread:  Batch rename


jovball (User)   Posted on: 09-Jan-2019 21:53:00.
I have about a dozen wide tables with columns that have the same naming prefix. As an easy example, imagine Customer table with columns named CustomerFirstName, CustomerLastName, CustomerPhone, CustomerEmail, etc.

I would like to remove all of those prefixes without doing "F2 > (edit) > Enter" more than 200 times. Is there any way to do this in the designer? This is for version 5.4.2.
daelmo (Support Team)   Posted on: 10-Jan-2019 05:58:11.
Hi Joel,

You could write a plugin.

Another way is to use the Element Search. It's commonly used for search objects into the project, but you also can perform actions in such queries. To do that:

1. Open Menu Project -> Search for Elements (Ctrl+F3).
2. In 'Element Type' select 'Enumerable'
3. Write this in the query area:
Code:
var entity = p.EntityModel.Vertices.FirstOrDefault(e=>e.Name=="Customer");
var prefix = entity.Name;

var fields = p.GetAllFieldsForGroupableModelElement(entity);
var newNames = new List<String>();
foreach(var f in fields)
{
    f.Name = f.Name.Replace(prefix, string.Empty);
    newNames.Add(f.Name);        
}

return newNames;

4. Click 'Run Query'. That's it.

Above example would run it for just one entity named 'Customer'. If you want to run on every entity in the project, this would be the query:
Code:
var newNames = new List<String>();
var allEntities = p.EntityModel.Vertices;

foreach(var entity in allEntities)
{
    var prefix = entity.Name;

    var fields = p.GetAllFieldsForGroupableModelElement(entity);    
    foreach(var f in fields)
    {
        f.Name = f.Name.Replace(prefix, string.Empty);
        newNames.Add(entity.Name + "." + f.Name);        
    }
}

return newNames;


Hope that helps Wink


jovball (User)   Posted on: 10-Jan-2019 16:12:19.
Yes, that's exactly what I need. For some reason, I completely forgot about element search.