Updating tables/fields not associated with a form

david.weeks
Member Posts: 96
Hello All,
What approach should I take to update a field on a table that is not associated with the form I am using?
i.e. When pressing a button on my form, I want to update various fields in other tables within Navision.
Any ideas?
Thanks
What approach should I take to update a field on a table that is not associated with the form I am using?
i.e. When pressing a button on my form, I want to update various fields in other tables within Navision.
Any ideas?
Thanks
0
Comments
-
create a record type variable of the table that you want to update and insert code on the OnPush trigger:
EG.
CLEAR(Table);
Table.Field := somethinig;
Table.MODIFY;0 -
Personally I create a function so I can place all commands in one place.
you need to declare a variable of type record and the table number of the table you wish to update.
You must then tell the system which record in the table you want to update. there are many ways to acheive this but the simpliest is to use the get command. This however relies on you having all the fields that are used in the primary key.
so, Lets say you wanted to update the customer record with a name change from a sales order:
Create a variable:
Name Datatype (cant remember last title)
Cust Rec Customer (table 18 )
based on using a button, on the "on push ()" trigger you would put the following:
Cust.get("Sell-to customer no.");
Cust."name":="Sell-to Customer name";
Cust.Modify;
If you do not have all the data required for the key fields, i.e. the sales line table then you would have to do something like this:
Create a variable:
Name Datatype (still cant remember last title)
SalesLine Rec sales Line (table 37 )
based on using a button, on the "on push ()" trigger you would put the following:
SalesLine.Setrange("Document type","document type"::Order;
SalesLine.Setrange("Document No.","No.");
if SalesLine.find('-') //tells the system to use the first match found
OR
if SalesLine.find('+') //uses the last line found
then
Salesline."somefield":="SomeUpdatefield";
SalesLine.Modify;
It then gets a bit more complex when you want to amend ALL lines found that match the filters so it would look something like this:
SalesLine.Setrange("Document type","document type"::Order;
SalesLine.Setrange("Document No.","No.");
if SalesLine.find('-') then
repeat
Salesline."somefield":="SomeUpdatefield";
SalesLine.Modify;
until salesLines.next=0;
Hope this helps explain things a little
DeanRemember: Keep it simple0 -
Hello All
Yes, this certainly helps and I have already had some sucess with doing what I require.
Dean - Thanks for your post, this will be most beneficial.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