Another user has modified the record for this Purchase Line

kamranshehzadkamranshehzad Member Posts: 165
Hi

I am trying to update a purchase ordere line record in a code unit and after it updates it, i tried to post it and get this error.

Another user has modified the record for this Purchase Line after you retrieved it from the database. Enter your changes again in the updated window, or start the interrupted activity again. Identification fields and values: Document Type='Order',Document No.='94011',Line No.='20000'
//code to modify purchase line 


  IF RecPurchaseLine.FINDSET THEN BEGIN
     IF RecPurchaseLine.Quantity <= OrderedQty THEN BEGIN
        tempQtyRec := RecPurchaseLine."Qty. to Receive";
        RecPurchaseLine.VALIDATE(Quantity, OrderedQty);
        RecPurchaseLine.VALIDATE ("Qty. to Receive" ,tempQtyRec); // Validate n update field value
        RecPurchaseLine.MODIFY;                   // modify record set.
        COMMIT;
     END;
  END;


// code to process order to receipt
ProcessPoToReceipt(DocumentNo : Text[20];DocumentType : Text[30]) RetMsg : Text[1000]
IF DocumentType = 'Order' THEN BEGIN
  CLEAR(RecPurchaseHeader);
  RecPurchaseHeader.INIT;
  RecPurchaseHeader.SETFILTER("No.",DocumentNo);
  RecPurchaseHeader.SETFILTER("Document Type",DocumentType);


  IF RecPurchaseHeader.FIND('-') THEN BEGIN
     RecPurchaseHeader.Receive := TRUE;   // SETTING PROPERTY TO RECEIVE
     RecPurchaseHeader.Invoice := FALSE;
     IF cuPurchPost.RUN(RecPurchaseHeader) THEN BEGIN
        MESSAGE('processed');
        RetMsg := 'Receipt Created Successfully';
     END 
      ELSE BEGIN
        ERROR(GETLASTERRORTEXT);
        RetMsg := GETLASTERRORTEXT;
     END;
  END;
END;


Please share your views on this.

regards,
KS

Answers

  • matttraxmatttrax Member Posts: 2,309
    Basically, you're modifying the record twice.

    So you've retrieved a record from the database.
    Something changes that record.
    It tries to change it again, but it sees that it doesn't have the same version of the record that has been written back to the database in the step above. Since it doesn't know what needs to change anymore it gives an error.

    Solution, change the way your code works, or retrieve the record from the database again. There might be other solutions, but those are the two that I'm aware of.

    Hope that's enough to get you started.
  • kamranshehzadkamranshehzad Member Posts: 165
    Ill modify my code again. well when you INIT a record, doesn't it get the fresh copy of table. if it doesn't then how do I refresh the Record. I can't see any method.

    Please comment on this..

    regards,
    KS
  • matttraxmatttrax Member Posts: 2,309
    So if you had a sales line that you had to modify, you would do this.
    NewSalesLine.GET(OldSalesLine."Document Type", OldSalesLine."Document No.", OldSalesLine."Line No.");
    //Make changes to NewSalesLine
    NewSalesLine.MODIFY;
    

    This will retrieve a new copy of the record from the database. You might even be able to use the same record variable.
  • kamranshehzadkamranshehzad Member Posts: 165
    Ah.. its simple..a ny way i fixed the code... but this is useful. i should have thought by myself..

    thanks alot.

    regards,
    KS
  • HayanHayan Member Posts: 110
    hi kamranshehzad,

    I am facing the same problem, all of the sudden the posting of purchase order was working then it stopped saying at the beginning that another user has modified the purchase header record then when i press ok and i try to post again it says that purchase line already exists.

    appreciate you help on this

    Best
    HAYAN
  • kamranshehzadkamranshehzad Member Posts: 165
    hi
    you need to put down your code here as there may be a different reason. I was modifying the same record twice i believe.
    it also happens when you get a record, and try to change any primary key field of it then you get the same error as well.

    As you said that first you get another user has modified the record and then you get purchase line already exists in that case, please check the following.
    1- when you try to post first time, are you modifying the same record twice or are you trying to modify the primary key.
    if you are trying to modify primary key field(s) then you will have to use two record variables.
    2- Before second try to post when you get purchase line already exists, check if PurhcaseHeader."Posting No." is populated?
    If i remember i had similar error and i cleared "posting no." field and it worked.

    add your code with little details what you are trying to achieve, so that someone can advise you better.

    regards
    KS
Sign In or Register to comment.