Using Virtual Fields

Follow

There are often times when you want to make use of a computed field in your documents, for example, your document might have FirstName and LastName fields on it, but you want to output a FullName field. Of course you can easily do this in your own application code, but LDC Via also offers the ability to create a “virtual” FullName field.

You manage virtual fields in a collection in the Database Viewer page and they require four pieces of information:

The field name, the field label, whether it will be treated as a “key field”, and finally the applicable field “formula”.

Hopefully, the first three attributes are obvious in their meaning, but the formula requires a specific format of JSON data to be entered.

In our example of building a FullName field, we are going to enter three elements for the formula:

[{
  "type": "docfield",
  "field": "FirstName"
},
{
  "type": "string", "value": " "
},
{
  "type": "docfield",
  "field": "LastName"
}]  

What we are building is a simple JSON array of commands that get processed one after another to build a new field value. So in the example above, we first get a "docfield" called FirstName, then we append a literal string value of " ", and finally we get a second "docfield" called LastName. 

Now, whenever a document from this collection is accessed it will automatically have a virtual field appended to it for you to use in the normal way.

Have more questions? Submit a request

Comments

Powered by Zendesk