Problem in updating Sales Invoice Header table through code

mkpjsrmkpjsr Member Posts: 587
Hi all,

While posting Sales Credit memo I am trying to update the Reason Code field of "Sales Invoice Header" table through code,but its not getting updated and the same is happening with partner license. Is there any way to do this without partner license.

Comments

  • SavatageSavatage Member Posts: 7,142
    a credit memo moves to the "Sales Cr.Memo Header" so are you saying you are applying the cm to a posted sales invoice and you want the applied invoice to be updated?

    what's your code?
  • mkpjsrmkpjsr Member Posts: 587
    Savatage wrote:
    a credit memo moves to the "Sales Cr.Memo Header" so are you saying you are applying the cm to a posted sales invoice and you want the applied invoice to be updated?

    what's your code?

    i have written the following code:

    IF SalesInvHeader.GET("Applies-to Doc. No.") THEN BEGIN
    SalesInvHeader."Reason Code":=Rec."Reason Code";
    SalesInvHeader.MODIFY;
    END ELSE BEGIN
    MESSAGE('Invoice No. not Found');
    END;
  • SavatageSavatage Member Posts: 7,142
    I'll assume you have the code on the OnAfterValidate of the "Applies-To Doc. No."
    I've added the message field so you can see when the value exists.
    If you try it again you'll see if you use the lookup to get the Invoice number- your code doesn't work.
    But if you copy the invoice number and paste it into the "Applies-To Doc. No." it will!
    the lookup is not triggering the OnAfterValidate.

    OnAfterValidate()
    IF SalesInvHeader.GET("Applies-to Doc. No.") THEN BEGIN
    SalesInvHeader."Reason Code":= "Reason Code";
    MESSAGE('%1',"Applies-to Doc. No.");
    SalesInvHeader.MODIFY;
    END ELSE BEGIN
    MESSAGE('Invoice No. not Found');
    END;

    But with a regular customer license you should then get an error saying you're not allowed to modify the Sales Invoice Header Table. Then (for me) I would then have to edit CU391 to allow me to change that field.
  • mkpjsrmkpjsr Member Posts: 587
    Savatage wrote:
    I would then have to edit CU391 to allow me to change that field.

    how can we do this??
  • SavatageSavatage Member Posts: 7,142
    Are you a partner or a customer?

    SalesInvoiceHeaderEdit(SalesInvoiceHeader : Record "Sales Invoice Header")SalesInvoiceHeader2 := SalesInvoiceHeader;
    SalesInvoiceHeader2.LOCKTABLE;
    SalesInvoiceHeader2.FIND;
    SalesInvoiceHeader2."Reason Code" := SalesInvoiceHeader."Reason Code";
    SalesInvoiceHeader2.MODIFY;
    SalesInvoiceHeader := SalesInvoiceHeader2;

    I know this makes the field editable but not sure if updating it thru code from another form will work. Testing is needed & your partner should help.
    I'm guessing it should still crash on -> SalesInvHeader.MODIFY;

    Ever thought about using the Credit & order Comments?
Sign In or Register to comment.