Code to Delete (Deleted Posted Sales Invoices)

Hello,

I think you can see from the code what I am trying todo.

MyDialog.OPEN(COMP.Name);
IF COMP.FIND(’-’) THEN REPEAT
SIL.CHANGECOMPANY(COMP.Name);
SIH.CHANGECOMPANY(COMP.Name);
SIL.SETRANGE(SIL.Description,‘Deleted Document’);
IF SIL.FIND(’-’) THEN REPEAT
IF SIH.GET(SIH.“No.”,SIL.“Document No.”) THEN
//SIH.DELETE;
//SIL.DELETE;
;
UNTIL SIL.NEXT =0;
MyDialog.UPDATE();
UNTIL COMP.NEXT=0;

But am getting following error “Too many key fields were specified so Sales Invoice Header could not be retrieved, The number of fields in the primary key is 1”.

Thanks

try

IF SIH.GET(SIL.“Document No.”) THEN

Hi,

Try the solution suggested by Mohana.

IF SIH.GET(SIL.“Document No.”) THEN

The syntax you were using was of SETRANGE/SETFILTER functions not of GET function.

First: The GET-command is not affected by SETRANGE at all.
SETRANGE and SETFILTER are used together with commands as FIND’s, COUNT’s and ISEMPTY.

2nd: Immideately after you got a line, your try to get the header.
When got the header you delete the line and the header.
When you get the next line belonging to the same header, that header is allready gone - and therefore the line(s) will not be deleted…