IF "Sales Header".FINDSET THEN REPEAT CLEAR("Sales Line"); "Sales Line".SETFILTER("Document No.", "Sales Header"."No."); IF "Sales Line".FINDSET THEN REPEAT //Clear The XML Port Object //Call the XML Port Object to export Orders. UNTIL "Sales Line".NEXT = 0; UNTIL "Sales Header".NEXT = 0;
Answers
Example:
Usually, SETRANGE and SETFILTER are used when you want to get more than one record.
You can get record via SETRANGE as:
Hope this helps.
Zohaib Ahmed
Dynamics NAV ERP Technical Consultant.
please like / agree / verify my answer, if it was helpful for you. thanks.
"Sales Header".SETRANGE("Sales Header"."No.",'109003');
IF "Sales Header".FINDFIRST THEN
BEGIN
// do something
END;
Hope this would be helpful
Zaid Tariq
Dynamics NAV/365 BC Developer at Dynamics 360
please like / agree / verify my answer, if was helpful.
To get a Sales Header you need 2 parameters, corresponding to the fields in the primary key in the correct order (and with correct types) For Sales Line you need 3 parameters to GET.
No need, neither for CLEAR nor for SETCURRENTKEY to GET a record. GET ignores filters and does not sort the one row it returns. Those statements don't hurt, but neither do they help.
Its a good approach to clear the variable and set the current key because we never know may be we are using that variable above for some other filters as well.
Zohaib Ahmed
Dynamics NAV ERP Technical Consultant.
please like / agree / verify my answer, if it was helpful for you. thanks.
https://msdn.microsoft.com/en-us/library/dd301056.aspx
"This function always uses the primary key for the table and ignores any filters."
This means that you won't need to CLEAR or SETRANGE or SETCURRENTKEY, as these will have no effect on GET.
Also, GET will return TRUE/FALSE depending on if a record is found.
IF "Sales Header".GET("Sales Header"."Document Type"::Order,'109003') THEN
//do stuff
"Sales Header".SETRANGE("Document Type","Sales Header"."Document Type"::Order);
"Sales Header".SETRANGE("Sales Header"."No.",'109003'); <<<<<<<<<< This should be a Loop and call all Lines from tables Sales Header and Sales Line
IF "Sales Header".FINDSET THEN BEGIN
REPEAT
filename := 'C:\Temp\' + FORMAT("Sales Header"."No.") + '.xml';
ClientFileName := FORMAT("Sales Header"."No.") + '.xml';
XmlFile.CREATE(filename);
XmlFile.CREATEOUTSTREAM(XmlOutStream);
XMLPORT.EXPORT(55667,XmlOutStream,"Sales Header");
XmlFile.CLOSE;
UNTIL "Sales Header".NEXT = 0;
END;
MESSAGE('Saved');
You can also set range if you want multiple orders in that range.
Also if you want to get order from 109003 onwards than do this
Please accept my answer if it helps.
Zohaib Ahmed
Dynamics NAV ERP Technical Consultant.
please like / agree / verify my answer, if it was helpful for you. thanks.
My XmlPort Should do: Call first row from Sales Header and Sales Line and after that next row till last Order, with codeunit save all orders as name ordernumer.xml to on Server look like this
the outer loop will iterate the whole sales header and the inner loop will iterate over the sales line of that sale order.
Zohaib Ahmed
Dynamics NAV ERP Technical Consultant.
please like / agree / verify my answer, if it was helpful for you. thanks.
Do like this
Feel free is still face problem.
please like / agree / verify my answer, if it was helpful for you. thanks.
Zaid Tariq
Dynamics NAV/365 BC Developer at Dynamics 360
please like / agree / verify my answer, if was helpful.
P.S - Writing a Code is not a big deal, you may get your desired output by doing many manipulations on the code but one thing i always suggest is to keep in mind is from Performance perspective. Always give priority to LOC(Line of Codes), dont write baseless lines even it's not doing anything to your outcome because one thing that's its doing for sure is it's increasing the time of the compiler to give the desired outcome.
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/
Its always a good and safe approach to initialize/clear the variable! PEACE!
Zohaib Ahmed
Dynamics NAV ERP Technical Consultant.
please like / agree / verify my answer, if it was helpful for you. thanks.
I will be coding a function for this.
Thanks for everything and keep on Coding
Zohaib Ahmed
Dynamics NAV ERP Technical Consultant.
please like / agree / verify my answer, if it was helpful for you. thanks.
Zaid Tariq
Dynamics NAV/365 BC Developer at Dynamics 360
please like / agree / verify my answer, if was helpful.
Codeunit Code
OnRun()
GetFilterNo(SalesHeader : Record "Sales Header")
SalesHeader.SETRANGE("No.",SalesHeader."No.");
FileName := 'C:\Temp\' + SalesHeader."No." + '.xml';
XmlFile.CREATE(FileName);
XmlFile.CREATEOUTSTREAM(XmlOutStrm);
XMLPORT.EXPORT(55667,XmlOutStrm,SalesHeader);
XmlFile.CLOSE;
Page Action Code
<Action1000000017> - OnAction()
CLEAR(ExportToXml);
ExportToXml.GetFilterNo(Rec);