Passing a filter from a codeunit to Report

MatStephensSandAMatStephensSandA Member Posts: 74
Hi all.

I am having an issue calling a report with filters from a codeunit.
I am trying to export a customer report filtered by salesperson code.
By and large the code works and when the customer is populated with a salesperson code the relevent filter is passed and the correct data exported to html. Result!
BUT.....It does not work when the salesperson is blank on the customer.
Here is a very basic example of what im tring to achieve:
FileDirectory := 'C:\'
Filename := FORMAT(Salesperson.Code);
Filepath := FileDirectory + FileName;
IF gvSalesperson.FIND('-') THEN REPEAT
  gvCustomer.SETCURRENTKEY("Salesperson Code");
  gvCustomer.SETRANGE("Date Filter",0D,DueDate);  
  gvCustomer.SETFILTER("Salesperson Code",Salesperson.Code);
  REPORT.SAVEASHTML(50375,Filepath,FALSE,gvCustomer);
UNTIL gvSalesperson.NEXT=0

Now when there is a salesperson code assosciated with the customer it works fine and the filter is successful.
When there is no salesperson associated on the customer rather than the report grouping all the customers with salesperson code of '' (Blank) in one report the filter does not seem to pass anything. And i get the entire customer base in one report.

How can i ensure that the filter of Salesperson code = '' is passed to the report??

THnaks in advance
M@
I have seen the future and it's egg shaped.

Answers

  • kapamaroukapamarou Member Posts: 1,152
    Try This:
    FileDirectory := 'C:\'
    Filename := FORMAT(Salesperson.Code);
    Filepath := FileDirectory + FileName;
    IF gvSalesperson.FIND('-') THEN REPEAT
      gvCustomer.SETCURRENTKEY("Salesperson Code");
      gvCustomer.SETRANGE("Date Filter",0D,DueDate); 
      //gvCustomer.SETFILTER("Salesperson Code",Salesperson.Code); <-Remove
      gvCustomer.SETFILTER("Salesperson Code",'%1',Salesperson.Code); //<-Add
      REPORT.SAVEASHTML(50375,Filepath,FALSE,gvCustomer);
    UNTIL gvSalesperson.NEXT=0
    
    
  • MatStephensSandAMatStephensSandA Member Posts: 74
    kapamarou i could kiss you!!!!
    That works a treat...
    It is true, you do learn something new everyday!

    one again thanks!
    M@
    I have seen the future and it's egg shaped.
  • kapamaroukapamarou Member Posts: 1,152
    You're welcome :D
Sign In or Register to comment.