Custom fields

Custom fields can be added to all entities in Uni Economy. To create a custom field you must use the "custom-fields" route to first define the field, and then activate it.

A custom field consists of a name, model and a datatype.

Example:

	{
	  "Name": "EksternLagerbeholdning",
	  "ModelID": 117,
	  "DataType": "258efb7d-5884-4329-8905-f2ac784267c8",
	  "Nullable": true
	}

Model and datatype are reference-fields and therefore has to be "looked up" before use.

Fetching available datatypes:

/api/biz/valuelists?expand=items&filter=code eq 'customfieldsqltypes'&hateoas=false

[{
		"Code": "customfieldsqltypes",
		"Description": "Datatypes for userdefined fields",
		"ID": 3,
		"Items": [{
				"Code": "bf049ca6-42e2-4ee1-882a-43ff8d986ce8",
				"Description": "Text limited to 255 characters",
				"ID": 90,
				"Name": "Small text field"
			}, {
				"Code": "f637df20-26dc-4419-9448-d9d9bcd839d5",			
				"Description": "Text field, unlimited number of characters",
				"ID": 91,
				"Index": 0,
				"Name": "Text"
			}, {				
				"Code": "1c396ebd-f770-498b-905b-47384f8e49cb",				
				"Description": "Whole number",
				"ID": 92,
				"Index": 0,
				"Name": "Number"
			}, {
				
				"Code": "258efb7d-5884-4329-8905-f2ac784267c8",				
				"Description": "",
				"ID": 93,
				"Index": 0,
				"Name": "Money"
			}
		]
	}
]

Fetching details about a model:

The endpoint "models" contains details about all entities in the system. To get the ID of the desired model you can do a query to fetch exactly one model

/api/biz/models?filter=name eq 'product'

[{
		"Admin": false,
		"Description": null,
		"ID": 117,
		"Label": "Product",
		"LabelPlural": null,
		"Name": "Product",
		"Shared": false,
	}
]

Creating a custom field

POST /api/biz/custom-fields

Example body:

	{
	  "DataType": "258efb7d-5884-4329-8905-f2ac784267c8",
	  "ModelID": 117,
	  "Name": "EksternLagerbeholdning",
	  "Nullable": true
	}

Example response:

	{
	  "ID": 1,
	  "Name": "EksternLagerbeholdning",
	  "Nullable": true,
	  "DataType": "258efb7d-5884-4329-8905-f2ac784267c8",
	  "ModelID": 117,
	  "StatusCode": 110100
	}

Activate the custom-field:

POST /api/biz/custom-fields/1?action=activate

Response: "200 - OK" indicates that the custom field has been activated and is ready for use.

After the field has been created and activated:

The custom field will have a prefix with "Custom" and will be located in the "CustomValues" subentity on the model you add the custom field to.

product example:

GET /api/biz/products/123

	{
		"ID": 123,
		"CustomValues": {
		  "CustomEksternLagerbeholdning": null
		}
	}

By using our services, you accept our Data protection declaration and Cookie policy