<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.dabo.leafe.com/index.php?action=history&amp;feed=atom&amp;title=Virtual_Fields</id>
	<title>Virtual Fields - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.dabo.leafe.com/index.php?action=history&amp;feed=atom&amp;title=Virtual_Fields"/>
	<link rel="alternate" type="text/html" href="https://wiki.dabo.leafe.com/index.php?title=Virtual_Fields&amp;action=history"/>
	<updated>2026-11-21T20:56:48Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.12</generator>
	<entry>
		<id>https://wiki.dabo.leafe.com/index.php?title=Virtual_Fields&amp;diff=4043&amp;oldid=prev</id>
		<title>Ed: Created page with &quot;This wiki article is a explanation of &lt;code&gt;Virtual Fields&lt;/code&gt; for bizobjs. Virtual Fields are seen and accessed just like regular data fields. The only exception is they a...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.dabo.leafe.com/index.php?title=Virtual_Fields&amp;diff=4043&amp;oldid=prev"/>
		<updated>2020-05-11T15:58:20Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;This wiki article is a explanation of &amp;lt;code&amp;gt;Virtual Fields&amp;lt;/code&amp;gt; for bizobjs. Virtual Fields are seen and accessed just like regular data fields. The only exception is they a...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;This wiki article is a explanation of &amp;lt;code&amp;gt;Virtual Fields&amp;lt;/code&amp;gt; for bizobjs. Virtual Fields are seen and accessed just like regular data fields. The only exception is they are not stored in the database. These fields are compiled at runtime. A good example of a virtual field is a subtotal for an order item.&lt;br /&gt;
&lt;br /&gt;
As an example, imagine the we have a table that keeps track of items added to an order. The table has several fields:&lt;br /&gt;
&lt;br /&gt;
: auto-incrementing ID fields&lt;br /&gt;
: ID for order&lt;br /&gt;
: ID for item&lt;br /&gt;
: Quantity&lt;br /&gt;
: Price&lt;br /&gt;
&lt;br /&gt;
This is all fine and dandy, except for we want an easy way to calculate the sub-total. We don&amp;#039;t store this information in the database because it&amp;#039;s redundant and we can get it from the quantity and price. So, we use a virtual fields to calculate the subtotal for a row dynamically. Take a look at the following code for the Bizobj:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
class OrderItemsBizobj(dabo.biz.dBizobj):&lt;br /&gt;
    def afterInit(self):&lt;br /&gt;
        self.addFrom(&amp;quot;orderItems&amp;quot;)&lt;br /&gt;
        self.addField(&amp;quot;ID&amp;quot;)&lt;br /&gt;
        self.addField(&amp;quot;OrderID&amp;quot;)&lt;br /&gt;
        self.addField(&amp;quot;ItemID&amp;quot;)&lt;br /&gt;
        self.addField(&amp;quot;Quantity&amp;quot;)&lt;br /&gt;
        self.addField(&amp;quot;Price&amp;quot;)&lt;br /&gt;
        &lt;br /&gt;
        self.DataSource = &amp;quot;orderItems&amp;quot;&lt;br /&gt;
        self.KeyField = &amp;quot;ID&amp;quot;&lt;br /&gt;
        self.NonUpdateFields=[&amp;quot;ID&amp;quot;]&lt;br /&gt;
    &lt;br /&gt;
       self.VirtualFields = {&amp;quot;SubTotal&amp;quot;: self.getSubTotal}&lt;br /&gt;
    &lt;br /&gt;
    def getSubTotal(self):&lt;br /&gt;
        return self.Record.Price * self.Record.Quantity&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, this seems pretty straight forward, right? The VirtualFields property is just a dictionary of key/value pairs where the key is the name of the field and the value is the function to call to get the value. You can now use the field &amp;lt;code&amp;gt;SubTotal&amp;lt;/code&amp;gt; as if it were a regular bizobj field. Every time we need to get the value of &amp;lt;code&amp;gt;SubTotal&amp;lt;/code&amp;gt; for a row, the &amp;lt;code&amp;gt;getSubTotal()&amp;lt;/code&amp;gt; function is called.&lt;/div&gt;</summary>
		<author><name>Ed</name></author>
	</entry>
</feed>