Problem modifying table data
karstenrobert
Member Posts: 27
Hi,
I'm fairly new to editing table data with reports.
My Problem is that I want to automatically change the data in a table with a report.
I created a report of the specific table I want to edit and included a request form which relates to the table with the data I want to choose the new location code from. The source expression is new_location_code.
The Code in the onaftergetrecord trigger looks like this:
IF order_line_rec.FIND('-') THEN BEGIN
order_line_rec."Location Code":=New_Location_Code;
MESSAGE('%1 , %2',"Location Code", New_Location_Code);
MODIFY;
END;
The real problem is that the report works fine(displays everything like it should look like) but does not write the new values in the table.
I tried lots of different ways to modify the table data with "order_line_rec.VALIDATE("Location Code",New_Location_Code);" and "order_line_rec.modify;" but somehow the table does not get modified.
Thanks in advance.
Karsten.
I'm fairly new to editing table data with reports.
My Problem is that I want to automatically change the data in a table with a report.
I created a report of the specific table I want to edit and included a request form which relates to the table with the data I want to choose the new location code from. The source expression is new_location_code.
The Code in the onaftergetrecord trigger looks like this:
IF order_line_rec.FIND('-') THEN BEGIN
order_line_rec."Location Code":=New_Location_Code;
MESSAGE('%1 , %2',"Location Code", New_Location_Code);
MODIFY;
END;
The real problem is that the report works fine(displays everything like it should look like) but does not write the new values in the table.
I tried lots of different ways to modify the table data with "order_line_rec.VALIDATE("Location Code",New_Location_Code);" and "order_line_rec.modify;" but somehow the table does not get modified.
Thanks in advance.
Karsten.
Karsten Frank
MCP - Dynamics NAV Developer
MCP - Dynamics NAV Developer
0
Comments
-
karstenrobert wrote:IF order_line_rec.FIND('-') THEN BEGIN
order_line_rec."Location Code":=New_Location_Code;
MESSAGE('%1 , %2',"Location Code", New_Location_Code);
MODIFY;
END;
Try:
IF order_line_rec.FIND('-') THEN BEGIN
order_line_rec."Location Code":=New_Location_Code;
MESSAGE('%1 , %2',"Location Code", New_Location_Code);
order_line_rec.MODIFY;
END;NAV - Norton Anti Virus
ERP Consultant (not just Navision) & Navision challenger0 -
Thanks for your answer.
But I tried that too. I rechecked it and sadly it does not work.
Karsten.Karsten Frank
MCP - Dynamics NAV Developer0 -
Hi Karsten,
Confirm the following
1) you have 2 Dataitems
OrderHdr
->OrderLine linked by Order No.
then your logic should be OrderLine OnAfterGetRecord
"location Code" := NewLoc;
MODIFY;
If you only have 1 dataitem
OrderHeader
then do the following OnAfterGetRecord
OrderLine.SETRANGE("Document Type","Document Type");
OrderLine.SETRANGE("Document No.","No.");
IF OrderLine.FIND('-') THEN BEGIN
....
....
END;
Hope this helps
0 -
Maybe I'm doing something fundamentally wrong:
Task:
Create a report with a single data item and a request form which lets you choose a new value to replace a field value in a table.
What I did.
1.I created a report which shows some values from this table including the location code which should be replaced with a new one.
This table contains production components for a manufacturing order.Which are take from a specific location code value.
The location code is outdated.
The report shows the information of the table production components correctly according to the filters set in the report view.
2. I attached a request form to the report which links to the table "location code" and returns the chosen new location code as a variant "new_location_code" (source expression)
3. I included a field for new_location_code in the report to check if the chosen location from the request form is correctly retrieved.
And that also works. The report displays the old location code from the table production components and the "new_location_code" I want to use from the request field.
4. Now I actually want to replace the old location code with the new_location code and write that back to the table.
5. I created a record variable of the table component line.
And inserted the following code to the onaftergetrecord trigger:
component_line_rec.INIT;
component_line_rec.SETRANGE(Status);
//MESSAGE('%1',"Prod. Order No.");
order_line_rec.SETRANGE("Prod. Order No.");
IF component_line_rec.FIND('-') THEN BEGIN
MESSAGE('correct');
//component_line_rec.VALIDATE("Location Code",New_Location_Code);
component_line_rec."Location Code":=New_Location_Code;
//order_line_rec.MODIFY;
MODIFY;
MESSAGE('%1 , %2',component_line_rec."Location Code", New_Location_Code);
end;
Everything is displayed in the final Message as it should be.
component_line_rec."location code" is the same as new_location_code.
But somehow the modify does not write the new value for location code in the table production component.
I'm rather puzzled about that behavior.
Greeting,
Karsten.Karsten Frank
MCP - Dynamics NAV Developer0 -
have you tried RENAME instead of modify ?0
-
Isn't rename for changing primary keys and not for changing normal data fields. Location code is no primary key in this table. Although it is used in some secondary keys.
Karsten.Karsten Frank
MCP - Dynamics NAV Developer0 -
3 things.
1 Is tehre onlyu one component line pr Order line? If not you need to modifyall.
2. Please stop using the damn underscores.
3. the modify needs to be of the rec you are modifying, not the dataitem. "component_line_rec.modify"0 -
OK,
I did that from scratch and now it works as expected.
Probably I seriously need some vacation.
Thanks for your help.
Karsten.Karsten Frank
MCP - Dynamics NAV Developer0
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
- 327 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