Copy Field from sales line to header
lavanyaballurgi
Member Posts: 235
Hey Guys.. its Sunday & I am working to complete my assignment. well here is my issue
I want to concatenate data from first 5 lines of text field named "Bill Detail"(customized field) present in Sales line .. into a text field of sales header named "invnarration". My code works but it doesnt update the last line's data in header field. why?
Here is my code
lin_counter := 0;
lrc_SalesHeader.GET("Document Type", "Document No.");
lrc_SalesLine.SETRANGE("Document Type", "Document Type");
lrc_SalesLine.SETRANGE("Document No.", "Document No.");
lin_SalesLineCounter := lrc_SalesLine.COUNT;
IF lrc_SalesLine.FINDSET THEN
REPEAT
lin_counter += 1;
IF lin_counter < lin_SalesLineCounter THEN
ltx_Narration += lrc_SalesLine."Bill Detail" + ' '
ELSE
ltx_Narration += lrc_SalesLine."Bill Detail";
UNTIL (lrc_SalesLine.NEXT = 0) OR (lin_counter = 6);
MESSAGE(ltx_Narration);// just to check ltx_narration variable.
lrc_SalesHeader.InvNarration := ltx_Narration;
lrc_SalesHeader.MODIFY(FALSE);
I want to concatenate data from first 5 lines of text field named "Bill Detail"(customized field) present in Sales line .. into a text field of sales header named "invnarration". My code works but it doesnt update the last line's data in header field. why?
Here is my code
lin_counter := 0;
lrc_SalesHeader.GET("Document Type", "Document No.");
lrc_SalesLine.SETRANGE("Document Type", "Document Type");
lrc_SalesLine.SETRANGE("Document No.", "Document No.");
lin_SalesLineCounter := lrc_SalesLine.COUNT;
IF lrc_SalesLine.FINDSET THEN
REPEAT
lin_counter += 1;
IF lin_counter < lin_SalesLineCounter THEN
ltx_Narration += lrc_SalesLine."Bill Detail" + ' '
ELSE
ltx_Narration += lrc_SalesLine."Bill Detail";
UNTIL (lrc_SalesLine.NEXT = 0) OR (lin_counter = 6);
MESSAGE(ltx_Narration);// just to check ltx_narration variable.
lrc_SalesHeader.InvNarration := ltx_Narration;
lrc_SalesHeader.MODIFY(FALSE);
0
Answers
-
There are few tips for your code:
1) Why you are using the lin_SalesLineCounter at all?
2) Why you are getting the SalesHeader, when you already have it in Rec?
Cleared code:lin_counter := 0; lrc_SalesLine.SETRANGE("Document Type", "Document Type"); lrc_SalesLine.SETRANGE("Document No.", "Document No."); IF lrc_SalesLine.FINDSET THEN REPEAT lin_counter += 1; IF ltx_Narration <> '' THEN ltx_Narration := ltx_Narration + ' '; ltx_Narration := ltx_Narration + lrc_SalesLine."Bill Detail"; UNTIL (lrc_SalesLine.NEXT = 0) OR (lin_counter = 6); MESSAGE(ltx_Narration);// just to check ltx_narration variable. lrc_SalesHeader.InvNarration := ltx_Narration; lrc_SalesHeader.MODIFY(FALSE);0 -
Well your tips were valid i shud not use extra variable when i cab get table in .Rec.
By the way using you code I am getting this error
Microsoft Dynamics NAV Classic
The Sales Header does not exist.
Identification fields and values:
Document Type='Quote',No.=''
OK
0 -
Of course, I made a mistake... look at last two lines. These must be over Rec too. But I expected that you can notice that... sorry, it was not intended...
InvNarration := ltx_Narration; MODIFY(FALSE);
0 -
I noticed that but then just putting Invnarration will give me an error that its an unknown variable. No?0
-
I am still learning about forms... so please dont mind if I ask stupid questions...0
-
Or may be I placed the code @ wrong place.... I put it on "Bill Details" - OnValidate().
right?0 -
It all depends. Depends on when you want to update the value. Of course, there are wrong places and correct places. But this must be decided on whole logic. Of course, question is, if the code should be on form or rather on table, because you want to update the data regardless form you use. And another question is, if you want to update the data in header when line is changed or somewhen else...0
-
That was a good reply

well I want to update the salesheader.invnarration field everytime someone enter data in salesline."Bill detail".
Shall I put the code on "Bill Detail" - OnValidate? Or you can propose me a better location?0 -
There is one rule: if possible, not modify other tables from OnValidate trigger. Because it is separate transaction from OnModify, and if OnModify will fail, the modified data in other tables will be still there (commited). Thus it could lead potentially to inconsistency. Of course, if you will call the code from Lines, the Rec will be the line, not header and you need to modify the code, or just call function doing that over header record (add function to header, call it from the line). Of course, you need to think about one thing- if you are reading the lines, you do not see the last change you did, which triggered the change (it is not written into databse yet). Thus you need to go around it somehow... ;-)0
-
Ok... that was a good learning ... And in Header where should I call the function? Invnarration - OnValidate() ?
If I want to update Invnarration before posting the invoice so where should I put the code? Codeunit 80 or 81?0 -
Ok I found a workaround. I created a ASSISTBUTTON on InvNarration field. and put my code there. It works fine but I need to instruct the user to click on assist button before posting invoice. Cant i put this code somewhere where this will update the Invnarration field automatically before posting?0
-
You canput it e.g. into Release function of the document. It is called each time the document is released, e.g. before posting.0
-
But Invoice can be posted directly without need of releasing. Basically all sales invoices are posted from invoice form & not sales order form.
Why its not a good idea to put the codes in codeunit which runs after we push "post" button?0 -
Release is done automatically when posting the document (if it is not already released manually), before posting rutine start... ;-) just look into the codeunit... 8)0
-
Well yes... I could see now that all invoice & orders are released before its posted... and I kept my code in release codeunit & it works =D>0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K 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
- 329 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
