First row on XmlPort

ozkan
Member Posts: 5
Hi everyone,
I have a little problem with C/Side coding on XMLport.
What should I do for call to first row from Sales Header and Sales Line
this is my code for Manuel order number
"Sales Header".SETRANGE("Document Type","Sales Header"."Document Type"::Order);
"Sales Header".SETRANGE("Sales Header"."No.",'109003');
I have a little problem with C/Side coding on XMLport.
What should I do for call to first row from Sales Header and Sales Line
this is my code for Manuel order number
"Sales Header".SETRANGE("Document Type","Sales Header"."Document Type"::Order);
"Sales Header".SETRANGE("Sales Header"."No.",'109003');
0
Best Answer
-
Hi @ozkan !
Do like thisIF "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;
Feel free is still face problem.
please like / agree / verify my answer, if it was helpful for you. thanks.Best Regards:
Zaid Tariq
Dynamics NAV/365 BC Developer at Dynamics 360
please like / agree / verify my answer, if was helpful.6
Answers
-
You can use GET function if you want to get first row only.
Example:"Sales Header".SETCURRENTKEY("No. "); IF "Sales Header".GET(109003) THEN BEGIN //your code END;
0 -
As @ridz_robbin said if you want to get only first row (one record) then GET is the right way to do. Before using GET make sure to clear your variable and use SETCURRENTKEY.
Usually, SETRANGE and SETFILTER are used when you want to get more than one record.
You can get record via SETRANGE as:"Sales Header".SETRANGE("Document Type","Sales Header"."Document Type"::Order); "Sales Header".SETRANGE("Sales Header"."No.",'109003'); IF "Sales Header".FINDFIRST THEN BEGIN // do something END;
Hope this helps.Best Regards
Zohaib Ahmed
Dynamics NAV ERP Technical Consultant.
please like / agree / verify my answer, if it was helpful for you. thanks.1 -
This is not really a good idea to use SETRANGE if you are sure that there is always a single record. Use SalesHeader.GET (109003) to get single record or
"Sales Header".SETRANGE("Sales Header"."No.",'109003');
IF "Sales Header".FINDFIRST THEN
BEGIN
// do something
END;
Hope this would be helpfulBest Regards:
Zaid Tariq
Dynamics NAV/365 BC Developer at Dynamics 360
please like / agree / verify my answer, if was helpful.1 -
ridz_robbin wrote: »You can use GET function if you want to get first row only.
Example:"Sales Header".SETCURRENTKEY("No. "); IF "Sales Header".GET(109003) THEN BEGIN //your code END;
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)"Sales Header".GET("Sales Header"."Document Type"::Order,'109003');
For Sales Line you need 3 parameters to GET.Before using GET make sure to clear your variable and use SETCURRENTKEY.
1 -
ridz_robbin wrote: »You can use GET function if you want to get first row only.
Example:"Sales Header".SETCURRENTKEY("No. "); IF "Sales Header".GET(109003) THEN BEGIN //your code END;
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)"Sales Header".GET("Sales Header"."Document Type"::Order,'109003');
For Sales Line you need 3 parameters to GET.Before using GET make sure to clear your variable and use SETCURRENTKEY.
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.Best Regards
Zohaib Ahmed
Dynamics NAV ERP Technical Consultant.
please like / agree / verify my answer, if it was helpful for you. thanks.2 -
GET ignores filters and keys.
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 stuff1 -
Thanks for all but it should be a loop and call first row and next row with order number already can I calling any order I want call all with a loop pre order new XmlFile this is my Codeunit code
"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');
1 -
@ozkan it should be like this:
CLEAR("Sales Header"); CLEAR("Sales Line"); "Sales Header".SETCURRENTKEY("Document Type", "No."); IF "Sales Header".GET("Document Type"::Order, 109003) THEN BEGIN "Sales Line".SETFILTER("Document No.", Your order no); //this will be your Sales Header document no. IF "Sales Line".FINDSET THEN REPEAT //your code UNTIL "Sales Line".NEXT = 0; END
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"Sales Header".SETFILTER("No.", '109003..'); IF "Sales Header".FINDSET THEN REPEAT // this will get the orders from 109003 till end;. UNTIL "Sales Header".NEXT = 0;
Please accept my answer if it helps.Best Regards
Zohaib Ahmed
Dynamics NAV ERP Technical Consultant.
please like / agree / verify my answer, if it was helpful for you. thanks.1 -
zohaibu95 Thank you but this is not my problem, i have trouble on XmlPort side my XmlPort Calling every Orders till end I tried so many filtering under <Sales Header> - Export::OnAfterGetRecord() trigger no function what did you mean should I do Filter on Codeunit side or on XmlPort?
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
0 -
Okay then simply all you need is to do this:
IF "Sales Header".FINDSET THEN REPEAT "Sales Line".SETFILTER("Document No.", "Sales Header"."No."); IF "Sales Line".FINDSET THEN REPEAT //your xml port code UNTIL "Sales Line".NEXT = 0; UNTIL "Sales Header".NEXT = 0;
the outer loop will iterate the whole sales header and the inner loop will iterate over the sales line of that sale order.
Best Regards
Zohaib Ahmed
Dynamics NAV ERP Technical Consultant.
please like / agree / verify my answer, if it was helpful for you. thanks.2 -
Hi @ozkan !
Do like thisIF "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;
Feel free is still face problem.
please like / agree / verify my answer, if it was helpful for you. thanks.Best Regards:
Zaid Tariq
Dynamics NAV/365 BC Developer at Dynamics 360
please like / agree / verify my answer, if was helpful.6 -
As @vaprog Suggested you need not have to do anything if you are writing a GET Statement.
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.Thanks
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/1 -
RockWithNAV wrote: »As @vaprog Suggested you need not have to do anything if you are writing a GET Statement.
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.
Its always a good and safe approach to initialize/clear the variable! PEACE!Best Regards
Zohaib Ahmed
Dynamics NAV ERP Technical Consultant.
please like / agree / verify my answer, if it was helpful for you. thanks.1 -
Hi Everyone, I have my problem solved with this code
SalesHeader.RESET; SalesHeader.SETCURRENTKEY("Document Type","No."); SalesHeader.SETRANGE("Document Type",SalesHeader."Document Type"::Order); SalesHeader.SETRANGE("No.",SalesHeader."No."); IF SalesHeader.FINDSET THEN BEGIN REPEAT FileName := 'C:\Temp' + SalesHeader."No." + '.xml'; XmlFile.CREATE(FileName); XmlFile.CREATEOUTSTREAM(XmlOutStrm); XMLPORT.EXPORT(55667,XmlOutStrm,SalesHeader); XmlFile.CLOSE; UNTIL SalesHeader.NEXT = 0; END; MESSAGE(Text001);
on Page Action
I will be coding a function for this.
Thanks for everything and keep on Coding1 -
You are welcome.Best Regards
Zohaib Ahmed
Dynamics NAV ERP Technical Consultant.
please like / agree / verify my answer, if it was helpful for you. thanks.1 -
Great
Best Regards:
Zaid Tariq
Dynamics NAV/365 BC Developer at Dynamics 360
please like / agree / verify my answer, if was helpful.1 -
Hello again me
my code is not efficient how can I do it more efficiently.
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);0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions