Hello!
In our case, a web order comes in via API (v2) and it can only set payment terms, so in parallel I set the payment method based on how the customer paid (gets that info via a custom api).
The problem is if I put e.g. card payment and the order is "invoiced", it should register that it has already been paid.
This does not happen if I set the payment method with AL.
However, it works fine if I select it manually one more time on the order.
So my question is, how can I set the payment method on a sales order with AL and everything will be correct all the way.
The example is when I get data to the custom API
trigger OnInsert() var OrderH: Record "Sales Header"; begin OrderH.Get("Sales Document Type"::Order, Rec.bcOrderNr); if OrderH."No." <> '' then begin OrderH.webOrderNumber := Rec.webOrderNr; if Rec.TvingandeFakturatyp <> '' then begin if LowerCase(Rec.TvingandeFakturatyp) = 'swish' then begin OrderH."Payment Method Code" := 'SWISH'; OrderH."Payment Terms Code" := 'FÖSRKOTT'; end else if LowerCase(Rec.TvingandeFakturatyp) = 'kort' then begin OrderH."Payment Method Code" := 'KORT'; OrderH."Payment Terms Code" := 'FÖSRKOTT'; end; end; OrderH.Modify(); end; end;
Thank you for the help Tech Lucky!
After more probing the problem was solved as you told me!
Hi David,
I wanted to provide an update regarding the issue, so I have tried updating the Payment Method Code and Payment Terms through AL code, and I did not encounter the same problem.
If the sales order can be posted manually with the same payment method and payment terms in your case then debug the code for both sales orders to compare the G/L entries for payment as suggested by Tech Lucky.
Regards
I am sorry I did not get your question previously,
Now I have understood and explored the code for the related fields on the Sales order page and table and I did not find anything that was Happening at the page level only, but yes you can try one more thing just change your code and validate the payments term code first and then payment method code as below :
OrderH.Validate("Payment Terms Code",'FÖSRKOTT'); // First
OrderH.Validate("Payment Method Code",'SWISH'); //second
OrderH.Validate("Payment Terms Code",'FÖSRKOTT');
OrderH.Validate("Payment Method Code",'KORT');
if this also does not help you then you need to debug your code in Both processes to find the difference.
one more thing if you are using different payment method codes and payment terms code in your manual process then you must compare the master setup as well for SWISH ,FÖSRKOTT etc.
Thanks for your answer and I tested it with no new result.
I probably described my problem poorly.
If the payment method is set with my code, the value seems correct visually on the order but after I post it and check the
General Ledger Entries, it is not listed as paid (Document type = Payment).
If I make an identical order and set the payment method manually, it will appear as paid in the General Ledger Entries.
With Code:
Manually:
if I understood your question correctly you mean you are getting the validation error while you select the payment method on an invoiced order right?
so you need the same validation if you are doing the same by your AL code, for that, you need to modify your code as Below :
trigger OnInsert() var OrderH: Record "Sales Header"; begin OrderH.Get("Sales Document Type"::Order, Rec.bcOrderNr); if OrderH."No." <> '' then begin OrderH.webOrderNumber := Rec.webOrderNr; if Rec.TvingandeFakturatyp <> '' then begin if LowerCase(Rec.TvingandeFakturatyp) = 'swish' then begin OrderH.Validate("Payment Method Code",'SWISH'); OrderH.Validate("Payment Terms Code",'FÖSRKOTT'); end else if LowerCase(Rec.TvingandeFakturatyp) = 'kort' then begin OrderH.Validate("Payment Method Code",'KORT'); OrderH.Validate("Payment Terms Code",'FÖSRKOTT'); end; end; OrderH.Modify(); end; end;
I hope this helps you, please verify my answer by Click YES
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