Find by array ?
Hello,
I have an array with a variable number of references of articles (ID1, ID3, ID8, ID13).
I'd like to see all the sales concerning these articles in a unique view.
Is it possible to select the records of a table by finding an array?
Thank you
4 replies
-
How are you filling your array? The only way I know it can be done is to create another table that you can copy the information to and then you can either go to that table or use it as the source for a View layout element. If you are interested in that I can help.
-
Thank you very much, Sean.
I am a publisher. Each [author] of my catalogue wrote several [works]. One work may be published in several [books]. each year, I have to calculate the royalties. So I need to select, within the [sales] of the year, those including a work of him. My report has to show the total sales relative to each title, and the total. And this for each author. (The brackets indicate the tables.) -
You're welcome Alain. I worked up some code based on your original post which was more general about wanting to select records based on items in an array. As I said, I personally don't know how you can filter records without iterating through the array and copying the information to another table. Here's an example of the code that you would put in the "On click" of a button...
delete (select TempTable);
let refArray := [ID1, ID3, ID8, ID13];
let arrCount := count(refArray);
for i in range(0, arrCount) do
let myItems := (select MainTable where Reference = item(refArray, i));
let itemsCount := count(myItems);
for j in range(0, itemsCount) do
let newRec := (create TempTable);
newRec.(Field1 := item(myItems, j).Field1);
newRec.(Field2 := item(myItems, j).Field2)
end
end;
openTable("TempTable")
1) The first line removes all records from the temporary table that you are copying records to.
2-3) The next two lines should be obvious.
4) This for-loop iterates through the items in your array.
5) Declares a variable to hold an array of records that match the "i" reference of your array.
6) Should be obvious
7) This for-loop iterates through the myItems array.
8) Creates a new record in "TempTable" to store the record from myItems.
9) Copies the field information from the myItems array to "TempTable". Do this for the fields you want to copy.
10) Same as 9.
11) Ends second for-loop.
12) Ends first for-loop.
13) Optional. This opens "TempTable" after the copying is complete.
If you need help, let me know.
-
Thank you so much Sean, for this code and the explanation. Indeed, it works in a button, this is a fantastic help.
I shall now try to deploy this over all the authors but this will cause no problem I think.
Have a great day !
Alain
Content aside
- 4 yrs agoLast active
- 4Replies
- 1294Views