Hello,
My company does quite a bit of dropshipment, and generally categorize everything based on customer & customer PO. Therefore, we would like our PO # to be available on sales documents.
I have created a custom field in "Sales Header" and "Sales Invoice Header" tables called "Purchase Order", and shown that value on the appropriate pages. Everything works there! However, I would like to be able to automatically copy our purchase order number to the "Sales Header" table, when the "Get Sales Lines" action is used. I see some documentation on records, however I cannot quite figure out how to modify the Sales Header from within the Purchase Header PageExtension (as this is the only place I can find that will allow me to set a trigger based upon the "Get Sales Order" action).
Can anyone help me? Thank you!
I think it's better to replace this field with an actual field.
In this way, when posting, as long as the id, type, and length are consistent, the value will be automatically transferred to the posted document.
Then there is the problem of assignment. From your Flowfield, you need "Sales Line"."Purchase Order No.". I'm not sure at what point you need this value, the following is just a simple example, you can modify it.
Source Code:
tableextension 50111 MyExtension2 extends "Sales Header" { fields { field(50101; "MyPOFlowfield"; Text[50]) { Caption = 'Flow PO #:'; DataClassification = CustomerContent; Editable = false; } } } tableextension 50113 MyExtension3 extends "Sales Invoice Header" { fields { field(50101; "MyPOFlowfield"; Text[50]) { Caption = 'Flow PO #:'; DataClassification = CustomerContent; Editable = false; } } } tableextension 50114 MyExtension4 extends "Sales Line" { fields { modify("Purchase Order No.") { trigger OnAfterValidate() var SalesHeader: Record "Sales Header"; begin if SalesHeader.Get(Rec."Document Type", Rec."Document Type") then if SalesHeader.MyPOFlowfield <> '' then begin SalesHeader.MyPOFlowfield := Rec."Purchase Order No."; SalesHeader.Modify(); end; end; } } }
Hope this helps.
Thanks.
ZHU
try
Rec.CALCFIELDS("MyPOFlowfield");
SalesInvoiceRecord1."MyPOFlowfield" := Rec."MyPOFlowfield";
yzhums Sorry, I did not do a good job explaining!
In my Sales Header tableextension, I have the following code:
field(50101; "MyPOFlowfield"; Text[50])
{
Caption = 'Flow PO #:';
FieldClass = FlowField;
CalcFormula = lookup("Sales Line"."Purchase Order No." where("Document No." = field("No.")));
}
I also have a PageExtension for the sales order, to display this value, and can see this value on the sales order. That part works! What I cannot figure out is how to transfer this value to the sales invoice once it's been posted. I have a TableExtension for the sales invoice, declaring a blank field in which I can put my new value, seen here:
field(50101; "MyPOFlowfield"; Text[50]) // Note this is not a flowfield, just a normal field.
{
Caption = 'Flow PO #:';
DataClassification = ToBeClassified;
}
I have attempted to directly assign the Sales Invoice field the value of the Sales Header flowfield, but it doesn't seem to work. Here is that code in the sales order PageExtension:
actions
{
modify(Post)
{
trigger OnAfterAction()
var
SalesInvoiceRecord1: Record "Sales Invoice Header";
begin
SalesInvoiceRecord1."MyPOFlowfield" := Rec."MyPOFlowfield";
end;
}
}
I think it does not work because either A) the flowfield is deleted after posting or B) because I cannot assign a flowfield calculated value to a "normal" value? I am not sure which. I've been trying for hours, if you would be able to help I'd be very grateful..
Hi, It seems that you are missing Record.CalcFields(Any [, Any,...]) Method before reading value in Flowfield.
More details: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/record/record-calcfields-method
Also, please note that the Flowfield is a virtual field, you cannot update it or assign a value to it.
Hope this helps.
Thanks.
ZHU
Mohana Yadav I'm hoping you can answer another question - I have created the custom flowfield which works great, but I cannot figure out to pass that value to the sales invoice.
I tried creating a standard field and a flowfield, and upon posting assign the value of the flowfield to the standard field. Then I would set the value of the sales invoice field equal to the standard field of the sales header. However, this doesn't seem to transfer over when I post.. Any suggestions?
I have a normal PO that is manually defined, and a Flowfield that is pulling from the Sales Lines. Before posting, they are both correct..
Here is a snippet of my code, within the Sales Order Page Extension:
actions
{
modify(Post)
{
trigger OnAfterAction();
var
SalesInvoiceRecord1: Record "Sales Invoice Header";
begin
SalesInvoiceRecord1.Reset();
Rec."My_PO" := Rec."My_PO_Flowfield"; //assign the Flowfield to the normal field (overwriting it)
SalesInvoiceRecord1."My_PO_Flowfield" := Rec."My_PO"; //then cast this records normal field to flow value
end;
}
}
Thank you! (For anyone else looking at this answer in the future, I also recommend Erik Hougaard's video on the subject, which helped me a lot)
You can create a flowfield to show the Purchase Order No. of Line on the header.
I'd like it to be searchable from the sales orders list, and more importantly I need it on the sales invoices after jobs have been completed. We search our manufacturer's configuration files based on our Purchase Order No., but customers will give us their Purchase Order No. when reaching out for help & technical assistance.
I am happy to copy it from the Sales Lines to the Sales Header, but I have to be able to do it from within the "Purchase Header" PageExtension, as that's where the trigger I was hoping to use is located.
Thanks!
Purchase Order No. is on the Sales Lines.
Is there any specific reason to have it on the header lines?
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,188 Super User 2024 Season 2
Martin Dráb 230,030 Most Valuable Professional
nmaenpaa 101,156