filter within an virtual function with confiforms
Asked by Florian Seibold:

I?ve understood, that when i use virtual functions, those are using from the left side and give this as an "output" to the right side. Therefore I?d thought when I now add something like a

"best before date"

to my

STOCKITEMS

and I want to see only the ones that are "good" I would take the code you give me and add:

```
...asFilteredBy(bestbeforedate:<[today])...
```

so it would look like this:

```
id.evaluateFormula([entry.ref2STOCKITEMS.asFilteredBy(bestbeforedate:<[today]).transform(quantity).join(+)])
```

But after adding this filter function nothing works anymore.

(field in view stays empty)

Here the updated complete sourcecode:

```
<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>
<ac:structured-macro ac:macro-id="bf8e8b42-2707-4dde-8ef8-87a21fc16066" ac:name="confiform-field-definition" ac:schema-version="1">
<ac:parameter ac:name="fieldName">bestbeforedate</ac:parameter>
<ac:parameter ac:name="fieldLabel">Best before Date</ac:parameter>
<ac:parameter ac:name="extras">dd.MM.yyyy</ac:parameter>
<ac:parameter ac:name="type">date</ac:parameter>
</ac:structured-macro>
</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="4876da9b-4a63-4368-bbd9-bca56e2200cf" ac:name="confiform-table" ac:schema-version="1">
<ac:parameter ac:name="formName">STOCKITEMS</ac:parameter>
<ac:parameter ac:name="enableGridEdit">true</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="661ea590-6870-4a0b-bc3d-684121a6606f" ac:name="confiform-table" ac:schema-version="1">
<ac:parameter ac:name="formName">PRODUCTS</ac:parameter>
<ac:parameter ac:name="enableGridEdit">true</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="9de30635-7420-4981-8ebb-cf63599d5af8" ac:name="confiform-field" ac:schema-version="1">
<ac:parameter ac:name="fieldName">id.evaluateFormula([entry.ref2STOCKITEMS.asFilteredBy(bestbeforedate:&lt;[today]).transform(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>
```

Thanks so much. Greetings Florian


Answers:
author: Florian Seibold
body: I was now, after hours of trial and error able to find a solution. If anyone needs it:

ef2Form1.asFilteredBy(startdate:\>\[entry._today\]).asFilteredBy(enddate:\<\[entry._today\]).transform(ref2Form2.ref2Form3.icon.**asAttachment.downloadPath.asImageLink).fixHtml**

That was the trick for me to have the Pictures shown again.

<br />

Greetings Florian


author: Alex Medved _ConfiForms_
body: Hi

At the moment the "asFilteredBy(FILTER)" function doe snot support ConfiForms filters, but only is able to do the string matching (partial or equals)

I will make a feature request to support true filtering expressions

Alex

comments: author: Florian Seibold
body: Thanks a lot. So I really found a limitation - for me almost impossible to belief :)  

Is there any workarround you could give me as a hint?  

Thanks a lot and greetings Florian


author: Alex Medved _ConfiForms_
body: We will improve this feature in the upcoming 3.0.0 version of ConfiForms (cloud version already has it)


author: Florian Seibold
body: We are now Updated to Version 3.2.0 of ConfiForms and it is still not working. You?ll have a hint for me?


author: Alex Medved _ConfiForms_
body: This has been implemented since 3.0.0

And filters could be applied on smart fields (as only these fields reference records and could be filtered by ConfiForms filters)


author: Florian Seibold
body: The field "ref2STOCKITEMS" in Form "PRODUCTS" is a Multi Value Smart Selection field holding only the ID to the Item in Form "STOCKITEMS".

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

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

The following code i?ve entered into an "Field"macro to sum up the stockitems of a product with bestbeforedate \< today.

```
id.evaluateFormula([entry.ref2STOCKITEMS.asFilteredBy(bestbeforedate:<[today]).transform(quantity).join(+)])
```


author: Florian Seibold
body: You?ll have a soulution for me so i could understand how to implement in my real problem?


author: Alex Medved _ConfiForms_
body: Simplified a bit the configuration from your comment earlier

And here is a demo - counts totals for products where best before date is in the past

<http://recordit.co/cTOJgOZ4Xj>

Hope it helps

Alex


author: Florian Seibold
body: Thanks a lot!  
Why is \[today\] here \[entry._today\] ??? What have i not read to not understand it????


author: Florian Seibold
body: If someone needs this too and Reminder for myself:  

If you?ll need to Filter for multiple Variables you could not chain the variables with AND like in the normal filters. You?ll need to add instead for each variable a .asFilteredBy(Variable:Value). block!!!!!


author: Florian Seibold
body: As It seems I need always a .transform() after the .asFilteredBy() function is there a trick to make preview items show as they were before filtering? In my case i want to filter like this:  
ref2Form1.asFilteredBy(startdate:\>\[entry._today\]).asFilteredBy(enddate:\<\[entry._today\]).ref2Form2.ref2Form3.icon

Where Form1 holds the values for startdate and enddate and in Form3 is a icon saved which sould be shown as a preview item as it was when i did no filtering.

So the above line doesen?t work. But i noticed I need a .transform():

ef2Form1.asFilteredBy(startdate:\>\[entry._today\]).asFilteredBy(enddate:\<\[entry._today\]).transform(ref2Form2.ref2Form3.icon)

But this gives me only a List with the names of the pictures and the PageId.

Thanks a lot in advance.


author: Alex Medved _ConfiForms_
body: That's really not what we have designed it - the asFilteredBy should be able to take any valid ConfiForms Filters expression. And this will be fixed soon.


Tags: confiforms

confluence-server

filter

server