filter within an virtual function with confiforms

Florian Seibold January 17, 2023

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

2 answers

2 accepted

0 votes
Answer accepted
Florian Seibold February 23, 2023

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.


Greetings Florian

0 votes
Answer accepted
Alex Medved _ConfiForms_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 17, 2023

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

Florian Seibold January 17, 2023

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

Alex Medved _ConfiForms_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 17, 2023

We will improve this feature in the upcoming 3.0.0 version of ConfiForms (cloud version already has it)

Florian Seibold February 22, 2023

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

Alex Medved _ConfiForms_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 22, 2023

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)

Florian Seibold February 23, 2023

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

 

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(+)])
Florian Seibold February 23, 2023

You´ll have a soulution for me so i could understand how to implement in my real problem?

Alex Medved _ConfiForms_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 23, 2023

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

Like Florian Seibold likes this
Florian Seibold February 23, 2023

Thanks a lot!
Why is [today] here [entry._today] ??? What have i not read to not understand it????

Florian Seibold February 23, 2023

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!!!!!

Florian Seibold February 23, 2023

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.

Alex Medved _ConfiForms_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 24, 2023

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.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events