Account flows
In the Accounts table, I have a view called Flows with the following script. It gives the correct dataset but would like to filter out from that dataset the selected account ledger line items (that is, xAccountId).
in other words, using another analogy, give me all products that a customer also purchased when they purchased Product X but do not list Product X.
"PURPOSE: SELECT ALL TRANSACTION LINE ITEMS WHERE JOURNAL ENTRY NUMBER EQUALS ALL JOURNAL ENTRY NUMBERS IN ACCOUNT";
let xAccountId := number(Id);
let xLedgerId := text(unique(concat((select Ledger)[Accounts.Id = xAccountId].Journal.Id)));
(select Ledger)[contains(xLedgerId, text(Journal.Id))]
52 replies
-
Take a look at this resonse. Some very helpful tips on how to manipulate arrays.
-
We can help build the code.
Question: This line:
let xLedgerId := text(unique(concat((select Ledger)[Accounts.Id = xAccountId].Journal.Id)));
You want to find all related Journal records to a particular Account record. They are related through the Ledger table. You can try writing the code:
let xLedgerId := text(concat(unique(Ledger.Journal.Id)));
This way uses the power of relationships and stays away from unnecessary select statements.
Now I don't understand what you want to do here:
(select Ledger)[contains(xLedgerId, text(Journal.Id))]
Aren't you just finding the same records that you have in xLedgerId?
-
Ok, now spending a few more moments looking at things, I think I understand this:
let xAccountId := number(Id); let xLedgerId := text(unique(concat((select Ledger)[Accounts.Id = xAccountId].Journal.Id))); (select Ledger)[contains(xLedgerId, text(Journal.Id))]
So line 2 finds all related Journal records to the current Account record.
Then in line 3 you want to find all Ledger records that have the same related Journal records but minus the Journal records found in line 2.
You can try, I'm thinking off the top of my head so I can't say for sure will work:
let xAccLedger := Ledger; let xAccJournal := xAccLedger.Journal; let journalrelatedLedger := (select Ledger [var j := Journal; xAccJournal[=j]]; journalrelatedLedger[var t := this; not xAccLedger[=t]]
I like to work with base records so I've changed the code to remove reference to Id.
Line 1 gets all related Ledger records to the current record. This is returned as an array of rid (record Ids).
Line 2 gets all related Journal records. This is returned as an array of rid (record Ids).
Line 3 finds all Ledger records that have the same Journal records. This will find records that would match line 1.
Line 4 is where we take the second array (of Ledger records) and subtract the first array (of related Ledger records to the current record) and we are left with records that have the same related Journal records to the current record but subtracts Ledger records related to the current record in Accounts.
I hope it works. If it doesn't can you upload a sample DB so I can test things out?
-
What about:
let myact := this; Ledger.Journal.Ledger[Accounts != myact]
-
said:
Not working yet.Can you write out an example using the records in your DB?
When I use Alain's example in your view in the Flow tab of the Groceries record (Account Id = 731) it seems to work for me.
Content aside
- Status Answered
- 1 yr agoLast active
- 52Replies
- 462Views
-
4
Following