Custom Fields

Questions about and code samples for custom order rules and validation within Select.
Post Reply
enendza
Posts: 75
Joined: Wed Oct 16, 2019 12:22 pm

Custom Fields

Post by enendza »

Hi -

When I look in our DB we have 7,000 ++ custom fields. Out of that 7,000 we have 1,044 that are NOT HIDDEN.

Are there any known concerns with making all the custom fields that we don't THINK are being used as HIDDEN?
Is there a SQL Statement that I can use to determine when and if the custom field has ever been used and we have data associated with it on some order? (custom fields date back to 2015)

Looking to reuse the custom fields that we already have in place but want to better understand the current usage of the fields. I don't want to change the name.

Any advice or articles would be much appreciated.

Thanks

Emma
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Custom Fields

Post by BobRichards »

As so far as modifying the "unused" custom fields to set them to Hidden, I think that's a good idea.

As so far as SQL to modify custom field, I wouldn't because it is not safe. The two SQL tables with the data have a Watermark column and this is internal logic to Select - stay away. You can use SQL if you want to read information only (pf.CustomFieldDefinition and pf.CustomFieldDefinition).

As in all things Select, the preferred way is to use the appropriate manager, get the items and edit them, then save the changes. In this example, I'll invert the setting of the Hidden bit then save it. Using the CustomFieldDefinitions method on the ICustomFieldsManager you can get at all the CustomFields with many filtering options.

Code: Select all

ICustomFieldsManager cfMgr = ss.GetService<ICustomFieldsManager>();
ICustomFieldDefinition cfDef
    = cfMgr.CustomFieldDefinitions
        .Where(t => t.Name == "1031ExchangeAccommodatorNumber_SP#")
        .First();

bool hidden = !cfDef.Hidden;
cfDef.Hidden = hidden;
cfMgr.ApplyChanges(cfDef);
Be aware that there may be a permission required to edit the values - I didn't check.
Bob Richards, Senior Software Developer, SoftPro
Post Reply