Programmatically creating Custom Fields

Discussions related to SoftPro Select Server development.

Moderator: Phil Barton

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

Programmatically creating Custom Fields

Post by danvanf » Thu Oct 22, 2020 2:52 pm

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: 1007
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Programmatically creating Custom Fields

Post by BobRichards » Thu Oct 22, 2020 3:37 pm

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 117 times
Other attributes are available by looking up ICustomFieldDefinition in the SDK Help file.
Bob Richards, Software Developer, SoftPro

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

Re: Programmatically creating Custom Fields

Post by danvanf » Thu Oct 22, 2020 4:22 pm

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