Hello,
I have one scenario where I have to delete the Sales line and order.
I have written a code where i am able to delete the header and line.
But the problem is if Sales header = 100 contains 3 sales line there in each line we have to check that fields:
Sales Line.Qty= Sales Line Temp. Call Off Qty IF true then
Doc No. Line No. Item No. Qty Call Off Qty
100 10000 ABC 2 2
100 20000 ABC 2 1 //this should be there in sales line along with header
100 30000 ABC 3 3
The bold sales lines has to be deleted instead of whole sale line and header.
Can u suggest how to write the code for this :
I have written the below code where whole sales header and lines are deleting.
Its an urgent requirement please tell how to rectify my code.
IF recCustomer.GET(pCustomerNo) THEN BEGIN
//lrecSalesLineTemp.DELETEALL;
lrecSalesLineTemp.RESET;
lrecSalesLineTemp.SETRANGE("Customer No.",pCustomerNo);
lrecSalesLineTemp.SETRANGE(Processed,TRUE);
IF lrecSalesLineTemp.FINDSET(FALSE,FALSE) THEN
BEGIN
lrecSalesLine.RESET;
lrecSalesLine."Document Type" := lrecSalesLine."Document Type"::Order;
lrecSalesLine.SETRANGE("Document No.",lrecSalesLineTemp."Document No.");
lrecSalesLine.SETRANGE("Line No.",lrecSalesLineTemp."Line No.");
lrecSalesLine.SETRANGE("No.",lrecSalesLineTemp."Item No.");
lrecSalesLine.SETRANGE("Sell-to Customer No.",pCustomerNo);
lrecSalesLine.SETRANGE("Outstanding Quantity",lrecSalesLineTemp."Outstanding Quantity");
IF lrecSalesLine.FINDSET THEN
BEGIN
REPEAT
IF ( lrecSalesLine.Quantity > lrecSalesLineTemp."Call Off Quantity") THEN
BEGIN
lrecSalesLine.Quantity := lrecSalesLine.Quantity - lrecSalesLineTemp."Call Off Quantity";
MESSAGE('%1', lrecSalesLine.Quantity);
lrecSalesLine.MODIFY(TRUE);
//lrecSalesLineTemp."New Sales Order No.":=lrecSalesLine."Document No.";
END
//here in else part i am going wrong as in this it has to check each and every line and if all lines satisfies the below condition then it should delete the lines along with header else only the particular line of that SO no which satisfies the below condition has to be deleted.
ELSE IF (lrecSalesLine.Quantity = lrecSalesLineTemp."Call Off Quantity") THEN
BEGIN
CLEAR(lrecSalesHeader);
IF lrecSalesHeader.GET(lrecSalesLine."Document Type",lrecSalesLine."Document No.") THEN
lrecSalesLine.DELETE;
MESSAGE('HELLO');
lrecSalesHeader.DELETE;
MESSAGE('hi');
END;
UNTIL lrecSalesLine.NEXT=0;
END;
END;
END;
*This post is locked for comments
[quote user="Pushpa "]
Hello,
I have one scenario where I have to delete the Sales line and order.
I have written a code where i am able to delete the header and line.
But the problem is if Sales header = 100 contains 3 sales line there in each line we have to check that fields:
Sales Line.Qty= Sales Line Temp. Call Off Qty IF true then
Doc No. Line No. Item No. Qty Call Off Qty
100 10000 ABC 2 2
100 20000 ABC 2 1 //this should be there in sales line along with header
100 30000 ABC 3 3
The bold sales lines has to be deleted instead of whole sale line and header.
Can u suggest how to write the code for this :
I have written the below code where whole sales header and lines are deleting.
Its an urgent requirement please tell how to rectify my code.
IF recCustomer.GET(pCustomerNo) THEN BEGIN
//lrecSalesLineTemp.DELETEALL;
lrecSalesLineTemp.RESET;
lrecSalesLineTemp.SETRANGE("Customer No.",pCustomerNo);
lrecSalesLineTemp.SETRANGE(Processed,TRUE);
IF lrecSalesLineTemp.FINDSET(FALSE,FALSE) THEN
BEGIN
lrecSalesLine.RESET;
lrecSalesLine."Document Type" := lrecSalesLine."Document Type"::Order;
lrecSalesLine.SETRANGE("Document No.",lrecSalesLineTemp."Document No.");
lrecSalesLine.SETRANGE("Line No.",lrecSalesLineTemp."Line No.");
lrecSalesLine.SETRANGE("No.",lrecSalesLineTemp."Item No.");
lrecSalesLine.SETRANGE("Sell-to Customer No.",pCustomerNo);
lrecSalesLine.SETRANGE("Outstanding Quantity",lrecSalesLineTemp."Outstanding Quantity");
IF lrecSalesLine.FINDSET THEN
BEGIN
REPEAT
IF ( lrecSalesLine.Quantity > lrecSalesLineTemp."Call Off Quantity") THEN
BEGIN
lrecSalesLine.Quantity := lrecSalesLine.Quantity - lrecSalesLineTemp."Call Off Quantity";
MESSAGE('%1', lrecSalesLine.Quantity);
lrecSalesLine.MODIFY(TRUE);
//lrecSalesLineTemp."New Sales Order No.":=lrecSalesLine."Document No.";
END
//here in else part i am going wrong as in this it has to check each and every line and if all lines satisfies the below condition then it should delete the lines along with header else only the particular line of that SO no which satisfies the below condition has to be deleted.
ELSE IF (lrecSalesLine.Quantity = lrecSalesLineTemp."Call Off Quantity") THEN
BEGIN
CLEAR(lrecSalesHeader);
IF lrecSalesHeader.GET(lrecSalesLine."Document Type",lrecSalesLine."Document No.") THEN
lrecSalesLine.DELETE;
MESSAGE('HELLO');
lrecSalesHeader.DELETE;
MESSAGE('hi');
END;
UNTIL lrecSalesLine.NEXT=0;
END;
END;
END;
[/quote]Can i know where put these codes .
we should put in sales header or sales line ON delete trigger
Hi
I agree with Mohana, Do this in phases...
First delete Lines and keep the loop until all the line with condition is met...
Finally you will be outside line loop then check if any line exist for True condition Do not delete header rec else Delete...
-------------------------
Hi Pushpa,
In you case, use 2 Sales Line record variables: one for loop, one for delete:
lRec_SalesLineLoop.SETRANGE("Document Type", lRec_SalesHeader."Document Type");
lRec_SalesLineLoop.SETRANGE("Document No.", lRec_SalesHeader."No.");
IF (lRec_SalesLineLoop.FINDSET) THEN
REPEAT
IF (lRec_SalesLineLoop.Quantity = lRec_SalesLineLoop."Call Off Quantity") THEN BEGIN
lRec_SalesLineDelete.GET(lRec_SalesLineLoop."Document Type", lRec_SalesLineLoop."Document No.");
lRec_SalesLineDelete.DELETE(TRUE);
END;
UNTIL (lRec_SalesLineLoop.NEXT = 0);
In else part delete only Sales Line and after finishing the loop of all lines with document no. check whether there are any lines existing with that order no.
if lines are not existing then delete the header
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156