Confiforms filter view dynamically with current page
Asked by Jens Jakobi:

Hello,

I have the following setup:

I have a form named "application" which holds data about an application. When a new entry is created, this form creates a new page tree for the new entry by using several IFTTTs macros. The pages themselves are using templates, which are passed to the IFTTT in the macro body. The form also creates entries for all sub forms.

I have a second form named "common" which holds some specific data about the applications, which are in the first form. The common form works as sub form of the application form. One of the stored fields in the common form is "page" where I store the confluence page on which the view is located.

So when I create an application I get a application form entry, a corresponding common form entry and a page for the common data. This setup works fine so far.

Now my new requirement is this:

I need to gather additional contact information to my common data. This data shall be organized or structured in a certain way (or in other words: I don't want to allow free text). To achieve this I created a second form named contacts which holds classic contact information like firstname, lastname, phone number, etc.

My requirement would be to use something like nested forms where I create a new application entry which creates a new commin entry and when I edit a common entry I can create a new contact entry "on-the-fly". But as this is not possible with Confiforms (no nested forms), I decided to try another way. My idea is this:

* I added a contact registration control and a contact view on the page where the common view is located.
* I create new contact entries on the common page and when the entry is created I just automatically set a hidden field "page" with the page I am currently showing using an IFTTT macro in the form.
* In the contact view on the common page I filter the entries by this page field and only show the entries which have the same page id as the page which is currently shown. I wanted to achieve this by using the \[entry._page\] variable.

This seemed to work, but I have a problem now. Because I use a page template in the initial creation of the common page the \[entry._page\] variable gets evaluated in that situation and I get a wrong page in my contact view filter. This results in an empty contact view as no entry has that page id.

I also tried a form filter macro, but in the end it was the same problem with the evaluation of the \[entry._page\] before the page is shown. But I do not want to show any form filter macro to the user (but i guess it can be set invisible).

My questions are now:

1. Is it possible to filter a view dynamically using the macro body of the view?
2. Is there any other way to filter the view dynamically based on the current page in my scenario where I use a space template to create the common page?

edit: As this setup is quite big I did not create a working example or attached storage format code. If this is necessary I can provide this.


Answers:
author: Alex Medved _ConfiForms_
body: You can use *asEntryRef* [function](https://wiki.vertuna.com/display/CONFIFORMS/Virtual+functions) in your template, so when the page gets created the function gets evaluated and you get the output as \[entry._page\]

```
[entry.id.asEntryRef(entry._page)]
```

(instead of \[entry._page\])

Alex

comments: author: Jens Jakobi
body: Hi Alex,

I just found that too. It works as intended! I hoped I would be faster than you with my answer, but I had no chance :D

Thank you!


author: Andrey Khaneev _StiltSoft_
body: Hello Jens,

Is it possible to use page title instead of page id?

Another possible solution is to use the [Table Filter](https://marketplace.atlassian.com/plugins/com.stiltsoft.confluence.plugin.tablefilter.tablefilter/cloud/overview) macro with the [@pageTitle variable](https://docs.stiltsoft.com/pages/viewpage.action?pageId=42239755#Tablefiltration-Filtertypesavailable).

And one more tip: maybe you could lookup two tables like in [these examples](https://docs.stiltsoft.com/display/TFAC/Default+automatic+presets#Defaultautomaticpresets-Lookuptablespreset).


Tags: confiforms

confluence-server

server