Getting salesperson from item ledger entry

What do you think the best way of getting the salesperson code from the item ledger table would be? Right now I run the report 10145 and export it to excel. I link the customer(source no.) to the customer table and get the salesperson that way. Problem is if the salesperson code has changed it doesn’t follow the invoice. So I thought I would just create a flowfield that finds the salesperson but since the document can be a service invoice or a sales invoice or a sales shipment, I can’t make it one field. Is that correct?

Hi, I think you can try to do a Case statement off of the Entry Type field. Then base your search on the Document No. on the respective table, perhaps? i.e. if Entry Type is Sale, find Document No. in Sales Shipment Header table and then pull the salesperson field from that table. I think that may work for you. Good luck!

I can’t use a case statement in a flowfield, so I would need to just put that logic where? I could write the code…


IF SalesInvoice.GET(“Document No.”) THEN BEGIN


What is the best way of doing this? Or is that wrong because of how many things hit this table? Maybe I should just tweak my report to go find the salesperson code instead of adding it to every entry of the item ledger table…

I don;t know what you mean by adding it to every entry of the item table.

This is just a report correct? Did you try your code on OnAfterGetRecord() of the ILE Dataitem?

If ILE.“Entry Type” = ILE.“Entry Type”:Sales then begin
If SalesInvHeader.Get(ILE.“Document No.”) then
SalesCode := SalesInvHeader.“Salesperson Code” else
SalesCode := ‘’;

SalesInvHeader->Record->Sales Invoice Header
SalesCode → Global Variable Type Code 10
Add field to your report with SalesCode as your SourceExp.

I have in the past needed to access this information when looking through the item ledger entry so I was thinking about adding a field directly into the table to do this. I was just asking if that isn’t the smartest thing since the table is so large. I just added logic to the report to go find the salesperson code. Thanks for your help…

Hi, I think Savatage’s code should work just fine as well. He’s using IF function while I thought of using the CASE function instead. I don’t think it’s necessary to add a Salesperson field to the ILE table

I would add a function into table 32 that uses a case to determine the source and return the sales person code or name as required.