Programmatically creating Custom Fields

Discussions related to SoftPro Select Server development.

Moderator: Phil Barton

Post Reply
danvanf
Posts: 54
Joined: Fri Nov 07, 2008 10:45 am
Location: Dayton, Ohio
Contact:

Programmatically creating Custom Fields

Post by danvanf »

Hello,

I have perused the site for some tips on creating a custom field programmatically. Failing to find a solution, it was time for a new topic.

During the initial startup of a server side app, I'd like to check for the existence of a text custom field, and if it doesn't exist, create it.

I'm not so concerned about checking the existence, we do that all the time, creating it, I've little clue. How is something like that accomplished?

Thanks!
I blog at http://DanVanFleet.com on SoftPro and other things
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Programmatically creating Custom Fields

Post by BobRichards »

Try this...

Code: Select all

public CreateCustomField(SelectServer ss)
{
    ICustomFieldsManager cfMgr = ss.GetService<ICustomFieldsManager>();

    // Create get a new custom field object and set its attributes.
    ICustomFieldDefinition cf = cfMgr.NewCustomFieldDefinition();
    cf.Context = cfMgr.AvailableContexts.Where(t => t.Name == "Order").First();
    cf.Name = "SpecialDate#";
    cf.Label = "The special date";
    cf.DataType = CustomFieldDataType.Date;

    // Save it to Select.
    cfMgr.ApplyChanges(cf);
}
2020-10-22_15-33-44.png
2020-10-22_15-33-44.png (5.17 KiB) Viewed 2597 times
Other attributes are available by looking up ICustomFieldDefinition in the SDK Help file.
Bob Richards, Senior Software Developer, SoftPro
danvanf
Posts: 54
Joined: Fri Nov 07, 2008 10:45 am
Location: Dayton, Ohio
Contact:

Re: Programmatically creating Custom Fields

Post by danvanf »

Ahh, you make it look so easy, and fast! Thanks a ton. :D
I blog at http://DanVanFleet.com on SoftPro and other things
Post Reply