Page 1 of 1

Custom Field Default values

PostPosted: Tue Dec 03, 2019 3:48 pm
by SBarnes
Is there a simple way to provide default values for custom fields on a debtor or product?

Re: Custom Field Default values  Topic is solved

PostPosted: Tue Dec 03, 2019 5:23 pm
by Mike.Sheen
SBarnes wrote:Is there a simple way to provide default values for custom fields on a debtor or product?


Using the SetValue method of the Valuecollection inside a handler for CreateEnd or CopyEnd is the only way right now...

So in the case of an Inventory item:

Code: Select all
Inventory.CustomFieldValues.SetValue<string>("My string custom Field", "My Plugin Name", "this is the new value");

Re: Custom Field Default values

PostPosted: Tue Dec 03, 2019 5:27 pm
by SBarnes
A nice to have and I realise this might create a fair bit of work, would be if you could define it in the plugin editor when the field is added as I was hoping to avoid code. I can add a service request if that will help?

Re: Custom Field Default values

PostPosted: Tue Dec 03, 2019 5:51 pm
by Mike.Sheen
SBarnes wrote:A nice to have and I realise this might create a fair bit of work, would be if you could define it in the plugin editor when the field is added as I was hoping to avoid code. I can add a service request if that will help?


By all means!

I had intended to have our standard maintenance business logic pattern to have a create from template function which may overlap this default custom field improvement you're asking for here.

To give an example as to how this would work, Inventory Maintenance would have a checkbox on it somewhere indicating the item is a template item. Template items are excluded from everything (you can't sell them, select them in searches, reports, the works) except for when creating a new item from a template item. The ribbon would have a new button "New from Template" which is a drop-down list showing you all the items which are marked as template items - this would essentially just load the template item, then copy it - including custom field values.

And that is a nice segue into highlighting an existing backlogged improvement relating to custom fields and copying - Add checkbox "Copy" for custom fields.

Hopefully I can make all 3 improvements play nice together.

Re: Custom Field Default values

PostPosted: Tue Dec 03, 2019 6:14 pm
by SBarnes
While what you are describing would work for strings and numbers my only question on the templates is how do you handle something like a custom date fields or dates full stop where you want to default them?

I do like you template idea though, I have seen customers do this with copying a product that never gets used, templates which you could even carry a little bit further where you could possibly define rules or conditions like when classification is XYZ use template ABC, which could definitely enforce default values for products or debtors that some customers want to do, this might however make it more complex than you were intending.

Re: Custom Field Default values

PostPosted: Wed Dec 04, 2019 6:59 am
by SBarnes
Hi Mike,

Having given this one some thought and whilst your idea is definitely I believe worth doing perhaps another way of going for what I was describing would be to extend the CustomFieldPlugin plugin to support an On New event and On Saving event that way although it doesn't avoid having to have code you would be able to use the first to set default values easily and the second to validate values for custom fields through out the system.