Hi @Pablo_DV !
Sorry for the late reply but I encountered some technical issues from my side of the screen … and then, it was simply too late for me to get back here …
So, from the screenshot you shared and the info you added, I came up with a 2 sample docs which seems to somewhat do what you’re looking for (I had improvise a little, especially when it comes to the Documents
) .
General Workflow
The workflow should be the same as yours (or at least, very similar)
- Complete the form with the relevant info concerning the tenant(s) (either both or just the first one)
- Submit the form
- Submitted form triggers an automation which pushes a button in the appropriated row in the table where the submissions are stored
- Button adds either 1 person or 2 (depending on the form submission) to the table
Persons
- Button adds 1 contract to the table
Contract
and links the contract to the person(s) previously created
- Button adds 3 documents to the table
Documents
and links each document to the contract previously created
- Automation mark the checkbox
Disable Button
as true to disable the button it just pushed (just in case )
Sample Doc 1
What I understood from your screenshot is that in the form you have a field for each bit of information for the Tenant 1
: First Name, Last Name, Phone Number, Email, etc …
And the same thing goes for the potential Tenant 2
.
When adding the tenant(s) to the Persons
table, you add a row per person (so 1 or 2) and their corresponding individual properties (First Name(s), etc…)
The Contract is added to the table Contracts
regardless of the amount of tenants submitted through the form. It’s always 1.
And per contract, you create 3 documents (with their own types, etc…).
So, in the sample just below, you’ll see a form ([View of Form Submissions]
) displaying only few fields from its source table [Form Submissions]
.
In the [Form Submissions]
you’ll see that I’ve externalise everything the button needs to do what it needs to do .
So, for each submission in the table :
-
[T - Full Name(s)]
returns the list of full names of the tenant(s) (which is either a list of 1 or a list of 2 full names)
-
T - First Name(s)
lists only the first name(s) of each tenant (either 1 or 2)
-
T - Last Name(s)
lists only the last name(s) of each tenant (either 1 or 2)
-
T - Some Thing(s)
lists only the “thing(s)” of each tenant (either 1 or 2)
The purpose of those fields is to group within a list the various properties tied each tenant (the 1st
item in the list being a property tied to the Tenant 1
and the 2nd item in the list would be the same property but tied to Tenant 2
, if any) so they can be added at once to the Persons
table when the button is pushed.
Of course, this means that each property filled out through the form which I didn’t illustrate here (Phone number, Email, etc…) would need their own field where they would be grouped using a formula similar to this one :
ListCombine(
thisRow.[T1 - First Name],
thisRow.[T2 - First Name]
).Filter(CurrentValue.IsNotBlank())
This is the formula in the field T - First Name(s)
and it simply creates a list with the value in thisRow.[T1 - First Name]
(the first name of Tenant 1
) and in thisRow.[T2 - First Name]
(the first name of Tenant 2
) and then filter that list by CurrentValue.IsNotBlank()
.
So, if the submission has a Tenant 1
and a Tenant 2
it will list both first names. But, if the submission has only a Tenant 1
(which seem to be the mandatory one in your case), it will only return the first name of the Tenant 1
.
And as we’re in the lists
world, items within a list can easily be counted (which will be useful later) .
The other fields used by the button you’ll see in the table are :
-
T - Contract
creates the name of the contract which is added to the Contracts
table by the button. The name is mostly created by manipulating lists
and depends on the number of full name(s) in the field T - Full Name(s)
.
If there’s only one full name in the list returned by T - Full Name(s)
, it means that only the info for Tenant 1
was completed and it will output something like: 📑 Daisy J.
.
If there are 2 full names, it will return something like: 📑 Charles X. & Moira M.
-
T - Docs
lists the names of the docs which will be added to the table Documents
(depending on the slider on the canvas)
-
Document Types
lists the types of each document added to the table Documents
through the button, in that order.
So, when the documents are created :
-
Document 1
(D-1
) will be linked to Type 1
-
Document 2
(D-2
) will be linked to Type 2
-
Document 3
(D-3
) will be linked to Type 3
As for the Button
formula, it looks like this :
RunActions(
Sequence(1,thisRow.[T - Full Name(s)].Count()).ForEach(
AddRow(
Persons,
Persons.Name,
thisRow.[T - Full Name(s)].Nth(CurrentValue),
Persons.[First Name],
thisRow.[T - First Name(s)].Nth(CurrentValue),
Persons.[Last Name],
thisRow.[T - Last Name(s)].Nth(CurrentValue),
Persons.[A Thing],
thisRow.[T - Some Thing(s)].Nth(CurrentValue)
)
),
AddRow(
Contracts,
Contracts.Name,
thisRow.[T - Contract],
Contracts.Persons,
Persons.Filter(Name.Contains(thisRow.[T - Full Name(s)]))
),
Sequence(1,[Documents Count]).ForEach(
AddRow(
Documents,
Documents.Name,
thisRow.[T - Docs].Nth(CurrentValue),
Documents.Contracts,
Contracts.Filter(Name.Contains(thisRow.[T - Contract])),
Documents.[Document Types],
thisRow.[Document Types].Nth(CurrentValue)
)
)
)
I’ve tried to comment it hoping it will help, but I think I need to work on my way of commenting formulas …
RunActions(
/* Action 1: Adds tenant(s) to Persons */
Sequence(1,thisRow.[T - Full Name(s)].Count()).ForEach(
/* thisRow.[T - Full Name(s)].Count() counts how many tenants need to be created
* Sequence(1,thisRow.[T - Full Name(s)].Count()) creates a list of numbers starting at 1 and ending at
* either 1 or 2 (depending on thisRow.[T - Full Name(s)].Count()).
* If there's only 1 tenant -> Sequence(1,thisRow.[T - Full Name(s)].Count()) returns 1
* If there are 2 tenants -> Sequence(1,thisRow.[T - Full Name(s)].Count()) returns a list of numbers
* (1, 2) and for each number in the list, add a row ... */
AddRow(
Persons,
Persons.Name,
thisRow.[T - Full Name(s)].Nth(CurrentValue),
/* thisRow.[T - Full Name(s)].Nth(CurrentValue) is the list in the field thisRow.[T - Full Name(s)]
* from which we only keep the Nth(CurrentValue) (and CurrentValue being each number
* returned by Sequence().
* For 1 tenant only, 1 item in thisRow.[T - Full Name(s)] and Sequence() outputs 1.
* So only 1 row is added and the value in Persons.Name will be
* thisRow.[T - Full Name(s)].Nth(CurrentValue) -> thisRow.[T - Full Name(s)].Nth(1).
* For 2 tenants, 2 items in thisRow.[T - Full Name(s)], Sequence() outputs (1, 2) -> 2 rows added.
* For the 1st row added thisRow.[T - Full Name(s)].Nth(CurrentValue) -> thisRow.[T - Full Name(s)].Nth(1)
* For the 2nd row added thisRow.[T - Full Name(s)].Nth(CurrentValue) -> thisRow.[T - Full Name(s)].Nth(2)
*/
Persons.[First Name],
thisRow.[T - First Name(s)].Nth(CurrentValue),
/* Same as before :) */
Persons.[Last Name],
thisRow.[T - Last Name(s)].Nth(CurrentValue),
Persons.[A Thing],
thisRow.[T - Some Thing(s)].Nth(CurrentValue)
)
),
/* Action 2 : Adds the contract to Contracts */
AddRow(
Contracts,
Contracts.Name,
thisRow.[T - Contract],
Contracts.Persons,
Persons.Filter(Name.Contains(thisRow.[T - Full Name(s)]))
/* Retrieve the person(s) previously created from Persons */
),
/* Action 3 : Adds documents to Documents */
Sequence(1,[Documents Count]).ForEach(
/* Same as for the Persons table.
* Sequence(1,[Documents Count]) returns a list of numbers (1, 2, 3) and for each number
* in the list, add a row ...
*/
AddRow(
Documents,
Documents.Name,
thisRow.[T - Docs].Nth(CurrentValue),
Documents.Contracts,
Contracts.Filter(Name.Contains(thisRow.[T - Contract])),
/* Retrieve the contract previously created */
Documents.[Document Types],
thisRow.[Document Types].Nth(CurrentValue)
)
)
)
Sample Doc 2
Same principle but everything done within the button (with still the help of the automation) .
I’m sorry for the length but I hope this helps !
As I probably forgot things here and there, don’t hesitate if you have any questions or if something is not clear