Hello,
I'm trying to write a part of codeunit that performs what this flowfield calcformula does:
Sum("Sales Invoice Line".Amount WHERE (Document No.=FIELD(No.)))
"Why can't you just put that in table?" I'm sure you're thinking... I've been tasked with optimising the system and I've thought of a pretty solid way of doing it (but I don't want to/need to write an essay explaining it =P~ )
I guess I could do this in about 20 lines of code, where I set multiple 'temporary' variables in a loop, but I'm sure there's a much more streamlined way of doing this. I'm trying to learn C/AL so I want to learn best practice where I can.
Comments
I don't really understand it, however. When I try and implement it, it seems to not do anything (though no error is returned).
I don't understand what is happening in the loop. Could you (or another reader) inform me how this works?
*** Edit ***
I think there may be a misunderstanding of what I would like:
I would like this codeunit to go through and write a value to the "Amount" field of the Sales Invoice Header in every line. This value is calculated by adding up the relevant Sales Invoice Lines records.
Any chance of a solution for the short- term problem though?
Something like this?
But to be honest it doesn't make much sense (moreover because should be more practical using a new FlowField on Sales Invoice Line table)...
Inspired by the first post, I wrote my own code, as follows
This works