Display associated content with conditional constraints.
In table HOME, there is a record with "nb" as 1. I want it to display the associated content with table copy, but without showing duplicate names, similar to what is shown in "show" (but excluding duplicate names). What are some ways to present this? Code or otherwise?
20 replies
-
I think the 'unique' parameter will do the job
unique | Ninox Docs (EN) -
As you can see there is no way to modify the many (N) side of a reference link. This field shows you all records linked to the current record. It is normally shown as a table, so you can see all linked records.
If you only want to see a unique list of the data in a particular field of a reference table then you will need to create a formula field that does that. Something like:
unique(Show.name)
-
said:
I would also like to write a piece of code in the copy table such that if "coffee" appears 3 times, the first occurrence of "coffee" is marked as 1, and the other two are marked as 0. Of course, this also applies to all duplicate values within the table. How should I write this code?You can have this done at the table level at the Trigger on new record. Or if you have a button that creates the records then it can be done there.
Since you are testing, create a button in the copy table and try writing code that:
1) creates an array of all records that have "coffee" in a the field.
2) create a variable that counts the length() of the array from step 1.
3) create a for loop using the range command that starts with 0 and ends with the variable from step 2.
3a) inside the for loop use an if statement that checks if the loop variable is equal to 0 then it puts 1 in the field, else it puts 0 in the field.
If all this works then we can work on removing the hard coding of "coffee" and make it more dynamic. Hint, another variable and a parent for loop.
-
You wrote:
let xxx := length((select copy).name); for i from 0 to xxx do if i = 0 then 1 else 0 end end
Here are the steps I suggested:
1) create an array of all records that have "coffee" in a the field.
Add a variable for this:
let coffeeRecs := select copy where name = "coffee";
3) create a for loop using the range command that starts with 0 and ends with the variable from step 2.
Well it looks like I was wrong about this. We need to use the coffeeRecs variable as we need access to the record Ids so we can modify fields in the records.
So the for loop would look something like:
for loop1 in coffeeRecs do let recIndex := index(coffeeRecs,loop1); loop1.fieldname := if recIndex = 0 then 1 else 0 end end
fieldname is the fieldname in the copy table you want to store the data of 1 or 0.
The final code would look like:
let coffeeRecs := select copy where name = "coffee"; for loop1 in coffeeRecs do let recIndex := index(coffeeRecs,loop1); loop1.fieldname := if recIndex = 0 then 1 else 0 end end
-
said:
For example, in the 'copy table,' 'beverage' is also considered a duplicate item. How can we achieve the same effect for these as well?That was the next step in the process. You need to:
1) create a new variable that stores the unique value of the 'name' field. This creates an array of values that we can now search on with a for loop. Now that you are putting a loop inside a loop, I find it helpful to name the loop variable loop1 and loop2.
2) create a new for loop that surrounds the current code. Since we used loop1 already, we can call this one loop2.
3) then you need to change the where in the select from "coffee" to the new loop variable, loop2.
4) you can change the variable 'coffeeRecs' to something else that makes more sense, but for now you can leave it.
-
said:
looking at the codeI can only do this....I'm sorry, I don't know how to start because I haven't understood the purpose of the square brackets yet.
-
said:
I don't know how to start because I haven't understood the purpose of the square brackets yet.Square brackets can be used in place of where in selects and to filter out any array.
let coffeeRecs := select copy where name = "coffee"; //would turn into let coffeeRecs := select copy[name = "coffee"];
The thing to know about square brackets is that in a select statement, the client copies over the entire table in the select then filters. Not a problem if you have a small dataset, but a problem if you have a large one.
But if you find yourself doing selects to the same table but filtering it differently then a way around this is to do 1 select into a variable then filter the variable as you move through your code.
let getAllRecs := select copy; let filterCoffee := getAllRecs[name = "coffee"]; let filterGrapes := getAllRecs[name = "grape"];
-
said:
Is name supposed to be some sort of category list,The actual situation is like this: I just simplified the steps to make it in text form.
said:
Can copy be made a child of Home?
Can copy be N:1 linked to Home?What are the aims of these two steps?
said:
So you need to figure out what is more important:I think HOME might serve as a dashboard, using its Y&N status to filter matching Y&N entries in the copy table, and then tally the number of identical values in the name field of the copy table.
Content aside
- Status Answered
- 5 mths agoLast active
- 20Replies
- 168Views
-
3
Following