ConfiForms: Creating a Sum of a Numeric Field on a dependent linked List
Asked by Florian Seibold:

Hi, I?m currently trying to sum up a Numeric field in in a second form which is in my actual form multiple times referenced. Therefore I?ve prepared my Dependent List Example. Maybe someone could give me a hint how this works :)

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/234676i1365784BAE9C35B1/image-size/large?v=v2&px=999 "image.png")

I?m trying to do this sum with the following Formula:

```
id.evaluateFormula([entry.ref2STOCKITEMS.quantity.join(+)])
```

Inside a table view with a Field macro. Here is the complete source:

```
<ac:structured-macro ac:macro-id="1f1aee26-aacb-40f7-908e-9604ffd3b148" ac:name="confiform" ac:schema-version="1">
<ac:parameter ac:name="formName">STOCKITEMS</ac:parameter>
<ac:rich-text-body>
<p>
<ac:structured-macro ac:macro-id="476e146e-845d-4a38-8345-35913d54987b" ac:name="confiform-field-definition" ac:schema-version="1">
<ac:parameter ac:name="fieldName">productcode</ac:parameter>
<ac:parameter ac:name="fieldLabel">Product Code</ac:parameter>
<ac:parameter ac:name="type">number</ac:parameter>
</ac:structured-macro>
</p>
<p>
<ac:structured-macro ac:macro-id="69c4e1b1-7e0e-4342-8927-f2aee7e24cf5" ac:name="confiform-field-definition" ac:schema-version="1">
<ac:parameter ac:name="fieldName">quantity</ac:parameter>
<ac:parameter ac:name="fieldLabel">Anzahl</ac:parameter>
<ac:parameter ac:name="type">number</ac:parameter>
</ac:structured-macro>
</p>
<p>
<br/>
</p>
<p>
<ac:structured-macro ac:macro-id="063bf5fd-7848-4811-9ed4-a0793f62255f" ac:name="confiform-field-definition" ac:schema-version="1">
<ac:parameter ac:name="fieldName">ref2PRODUCTS</ac:parameter>
<ac:parameter ac:name="fieldLabel">Refenrence to Product Form</ac:parameter>
<ac:parameter ac:name="values">[198190117|PRODUCTS|id|true||]</ac:parameter>
<ac:parameter ac:name="type">smartselect</ac:parameter>
</ac:structured-macro>
</p>
<ac:structured-macro ac:macro-id="de64c758-e230-4003-9c41-b3bf804d70e4" ac:name="confiform-ifttt" ac:schema-version="1">
<ac:parameter ac:name="extras5">true</ac:parameter>
<ac:parameter ac:name="condition">!productcode:[empty] AND id.queryCount(PRODUCTS:@self;productcode:[entry.productcode]):0</ac:parameter>
<ac:parameter ac:name="action">Create ConfiForms Entry</ac:parameter>
<ac:parameter ac:name="event">onCreated</ac:parameter>
<ac:parameter ac:name="title">productcode=[entry.productcode]</ac:parameter>
<ac:parameter ac:name="who">PRODUCTS:this</ac:parameter>
<ac:rich-text-body>
<p>Create Product if not exists</p>
</ac:rich-text-body>
</ac:structured-macro>
<ac:structured-macro ac:macro-id="22c80cf6-be76-4863-bab6-1bad22b18ae1" ac:name="confiform-ifttt" ac:schema-version="1">
<ac:parameter ac:name="extras5">true</ac:parameter>
<ac:parameter ac:name="condition">!productcode:[empty] AND ref2PRODUCTS:[empty]</ac:parameter>
<ac:parameter ac:name="action">Create ConfiForms Entry</ac:parameter>
<ac:parameter ac:name="event">onCreated</ac:parameter>
<ac:parameter ac:name="title">entryId=[entry.id]&amp;ref2PRODUCTS=[entry._func.queryAndSet(PRODUCTS:@self;productcode:[entry.productcode];id;created DESC LIMIT 1)]</ac:parameter>
<ac:rich-text-body>
<p>create Link to PRODUCT</p>
</ac:rich-text-body>
</ac:structured-macro>
<ac:structured-macro ac:macro-id="841e764d-82ad-453c-846a-0965cf0a98a0" ac:name="confiform-ifttt" ac:schema-version="1">
<ac:parameter ac:name="extras5">true</ac:parameter>
<ac:parameter ac:name="condition">!ref2PRODUCTS:[empty]</ac:parameter>
<ac:parameter ac:name="action">Create ConfiForms Entry</ac:parameter>
<ac:parameter ac:name="event">onCreated</ac:parameter>
<ac:parameter ac:name="title">entryId=[entry.ref2PRODUCTS] &amp; ref2STOCKITEMS=[entry.ref2PRODUCTS.ref2STOCKITEMS.transform(id).asList],[entry.id]</ac:parameter>
<ac:parameter ac:name="who">PRODUCTS:this</ac:parameter>
<ac:rich-text-body>
<p>create Link in PRODUCT</p>
</ac:rich-text-body>
</ac:structured-macro>
<p>
<br/>
</p>
<p>
<br/>
</p>
<p>
<br/>
</p>
<p>
<br/>
</p>
<p>
<br/>
</p>
<p>
<br/>
</p>
<p>
<br/>
</p>
<ac:structured-macro ac:macro-id="3ebcb3de-a752-4615-96d7-de00aabb445c" ac:name="confiform-entry-register" ac:schema-version="1">
<ac:parameter ac:name="formName">STOCKITEMS</ac:parameter>
<ac:rich-text-body>
<p>
<br/>
</p>
</ac:rich-text-body>
</ac:structured-macro>
</ac:rich-text-body>
</ac:structured-macro>
<ac:structured-macro ac:macro-id="f18ea0f4-5954-4644-af6b-ea523f4e3b7e" ac:name="confiform-table" ac:schema-version="1">
<ac:parameter ac:name="formName">STOCKITEMS</ac:parameter>
<ac:rich-text-body>
<p>
<br/>
</p>
</ac:rich-text-body>
</ac:structured-macro>
<ac:structured-macro ac:macro-id="a2be81c6-ce23-47b3-a2f3-0ae652a84c11" ac:name="confiform" ac:schema-version="1">
<ac:parameter ac:name="formName">PRODUCTS</ac:parameter>
<ac:parameter ac:name="registrationFormTitle">Produkte aus ABAS</ac:parameter>
<ac:rich-text-body>
<p>
<br/>
</p>
<p>
<br/>
</p>
<p>
<ac:structured-macro ac:macro-id="1198a13c-1ec3-4bf6-a963-776125c229cb" ac:name="confiform-field-definition" ac:schema-version="1">
<ac:parameter ac:name="fieldName">productcode</ac:parameter>
<ac:parameter ac:name="fieldLabel">Product Code</ac:parameter>
<ac:parameter ac:name="type">number</ac:parameter>
</ac:structured-macro>
</p>
<p>
<ac:structured-macro ac:macro-id="4570cf5d-18cd-4cf4-bfcd-88bda294ea33" ac:name="confiform-field-definition" ac:schema-version="1">
<ac:parameter ac:name="fieldName">productname</ac:parameter>
<ac:parameter ac:name="fieldLabel">Product Name</ac:parameter>
<ac:parameter ac:name="type">text</ac:parameter>
</ac:structured-macro>
</p>
<p>
<ac:structured-macro ac:macro-id="c8ab3ed3-3779-4dc1-b34b-f9db82c21ad9" ac:name="confiform-field-definition" ac:schema-version="1">
<ac:parameter ac:name="fieldName">description</ac:parameter>
<ac:parameter ac:name="fieldLabel">Beschreibung</ac:parameter>
<ac:parameter ac:name="type">text</ac:parameter>
</ac:structured-macro>
</p>
<p>
<ac:structured-macro ac:macro-id="4ec960ce-8894-4c42-961a-0d53a1744c3a" ac:name="confiform-field-definition" ac:schema-version="1">
<ac:parameter ac:name="fieldName">ref2STOCKITEMS</ac:parameter>
<ac:parameter ac:name="fieldLabel">StockItems referencing this Product</ac:parameter>
<ac:parameter ac:name="values">[198190117|STOCKITEMS|id|true||]</ac:parameter>
<ac:parameter ac:name="type">smartmultiselect</ac:parameter>
</ac:structured-macro>
</p>
<p>
<br/>
</p>
<ac:structured-macro ac:macro-id="83c05741-9f9b-46c7-a5c9-4c9e72fedf8a" ac:name="confiform-entry-register" ac:schema-version="1">
<ac:parameter ac:name="formName">PRODUCTS</ac:parameter>
<ac:rich-text-body>
<p>
<br/>
</p>
</ac:rich-text-body>
</ac:structured-macro>
</ac:rich-text-body>
</ac:structured-macro>
<ac:structured-macro ac:macro-id="cbc6b6b0-c35e-49fb-9fc1-bcbe8cae154c" ac:name="confiform-table" ac:schema-version="1">
<ac:parameter ac:name="formName">PRODUCTS</ac:parameter>
<ac:rich-text-body>
<p>
<br/>
</p>
</ac:rich-text-body>
</ac:structured-macro>
<ac:structured-macro ac:macro-id="a2924811-0747-4c5e-88b6-7268defddbf8" ac:name="confiform-table" ac:schema-version="1">
<ac:parameter ac:name="formName">PRODUCTS</ac:parameter>
<ac:rich-text-body>
<p>
<ac:structured-macro ac:macro-id="edc05a9a-0e5f-4054-9f2f-94e093b3f3e0" ac:name="confiform-field" ac:schema-version="1">
<ac:parameter ac:name="fieldName">productcode</ac:parameter>
</ac:structured-macro>?<ac:structured-macro ac:macro-id="4ed5470b-4b54-49cb-8def-f9bd04f6b19b" ac:name="confiform-field" ac:schema-version="1">
<ac:parameter ac:name="fieldName">productname</ac:parameter>
</ac:structured-macro>??<ac:structured-macro ac:macro-id="ec6a49ba-da5d-47ae-a4d1-d2b7bb651022" ac:name="confiform-field" ac:schema-version="1">
<ac:parameter ac:name="fieldName">id.evaluateFormula([entry.ref2STOCKITEMS.quantity.join(+)])</ac:parameter>
</ac:structured-macro>
</p>
</ac:rich-text-body>
</ac:structured-macro>
<ac:structured-macro ac:macro-id="e10a343c-3e45-4cae-880f-130f3c4150a5" ac:name="confiform-table" ac:schema-version="1">
<ac:parameter ac:name="formName">STOCKITEMS</ac:parameter>
<ac:rich-text-body>
<p>
<ac:structured-macro ac:macro-id="3cb573d1-2753-4321-8521-09f00d248894" ac:name="confiform-field" ac:schema-version="1">
<ac:parameter ac:name="fieldName">ref2PRODUCTS.ref2STOCKITEMS.transform(id).asList</ac:parameter>
</ac:structured-macro>
</p>
</ac:rich-text-body>
</ac:structured-macro>
```


Answers:
author: Alex Medved _ConfiForms_
body: Hi

As you have a multi-select field for ref2STOCKITEMS and it is of type smart select then you actually have no field, such as "quantity" in there... this is just an array of UUIDs referencing another form

Som the formula would be something like

```
id.evaluateFormula([entry.ref2STOCKITEMS.transform(quantity).join(+)])
```

Alex

comments: author: Florian Seibold
body: Thanks a lot. Is there any tutorial or compareable that brings me to a point that i can understand why which function works like they do? or is it just simply try until i?ve made every mistake that could be done? :)

Thanks a lot for your superb support :)


author: Alex Medved _ConfiForms_
body: I guess the best option is to draw your data model on the paper and understand how the forms are connected.

Multi-value fields hold an *array* of data... and in order to get to the properties of each stored item (in this array) the easiest way is to use transform function - see <https://wiki.vertuna.com/display/CONFIFORMS/Virtual+functions>

Alex


author: Florian Seibold
body: removed. New Topic


Tags: calculated-field

confiforms

confluence-server

link

server

sum