Pass FieldRef as Parameter to use in UPDATEALL

EdZ
Member Posts: 10
Hi,
having several years of experience in other ERP's I recently started working with NAV.
I'm trying to do the following :
In a Header Detail Object I have the Field Start_Date both in the header as in the line table.
When the value in the header has changed I want to update the lignes.
As I'm going to need to do this for several fields I thought of creating 1 update_lines procedure, with the Field to update as parameter
**********************************
Start Date - OnValidate()
**********************************
// Validate if start date has change
IF (TRUE) THEN
BEGIN
// Update Lines
Update_Lines( LFld_Start_Date );
END;
**********************************
Update_Lines(P_FieldRef : FieldRef)
**********************************
// Filter lines to show only related records
LR_Line.SETRANGE("Header Code");
// Check if any line exists
IF LR_Line.FIND('-') THEN
BEGIN
// Ask to update
IF ( DIALOG.CONFIRM (Text001, FALSE) ) THEN
BEGIN
// Replace value for all lines
LR_Line.MODIFYALL( P_FieldRef, P_FieldRef.Value );
END;
END;
At compiling this show the error :
A Field From a record variable was expected. For Example
Record.Field or
Customer.Name
I have tried passing the Field in different ways but with no result.
What is the prefered method of Updating Lines ?
Am I forced to write the same procedure for all header fields I want to distribute to the lines ?
Thanks
EdZ
having several years of experience in other ERP's I recently started working with NAV.
I'm trying to do the following :
In a Header Detail Object I have the Field Start_Date both in the header as in the line table.
When the value in the header has changed I want to update the lignes.
As I'm going to need to do this for several fields I thought of creating 1 update_lines procedure, with the Field to update as parameter
**********************************
Start Date - OnValidate()
**********************************
// Validate if start date has change
IF (TRUE) THEN
BEGIN
// Update Lines
Update_Lines( LFld_Start_Date );
END;
**********************************
Update_Lines(P_FieldRef : FieldRef)
**********************************
// Filter lines to show only related records
LR_Line.SETRANGE("Header Code");
// Check if any line exists
IF LR_Line.FIND('-') THEN
BEGIN
// Ask to update
IF ( DIALOG.CONFIRM (Text001, FALSE) ) THEN
BEGIN
// Replace value for all lines
LR_Line.MODIFYALL( P_FieldRef, P_FieldRef.Value );
END;
END;
At compiling this show the error :
A Field From a record variable was expected. For Example
Record.Field or
Customer.Name
I have tried passing the Field in different ways but with no result.
What is the prefered method of Updating Lines ?
Am I forced to write the same procedure for all header fields I want to distribute to the lines ?
Thanks
EdZ
0
Answers
-
I have solved my problem.
I found an example of update the lines in the Sales Header / Sales Line tables
In Header Table:
***************************************************************************
Tbl_Update_Budget_Line(P_FieldName : Text[100];AskQuestion : Boolean) L_Return : Boolean
***************************************************************************
L_Return := TRUE;
// Filtre pour montrer seule les lignes relatives
LR_Line.SETRANGE ( "Code", "Code" ) ;
L_UpdateLines := LR_Line.FIND ( '-' ) ;
IF L_UpdateLines AND AskQuestion THEN
BEGIN
IF NOT ( DIALOG.CONFIRM ( "Update lines?", FALSE) ) THEN
L_Return := FALSE ;
EXIT
END ;
IF L_UpdateLines THEN
BEGIN
// LOCKTABLE with SQL option
LR_Line.LOCKTABLE ( TRUE, FALSE ) ;
MODIFY;
LR_Line.RESET;
LR_Line.SETRANGE ( "Code","Code" ) ;
IF LR_Line.FIND ( '-' ) THEN
REPEAT
CASE P_FieldName OF
// Update Line
FIELDCAPTION ( "Date" ) :
IF LR_Line."Line No." <> 0 THEN
LR_Line.VALIDATE ( "Date", "Date" ) ;
FIELDCAPTION ( "Client No." ) :
IF LR_Line."Line No." <> 0 THEN
LR_Line.VALIDATE ( "Client No.", "Client No." ) ;
END ;
// Apply modifications
L_Return := LR_Line.MODIFY ( TRUE ) ;
UNTIL LR_Line.NEXT = 0;
END;
from the Field.OnValid trigger, call the function with the fieldcaption as parameter like:
Tbl_Update_Budget_Line( FIELDCAPTION ( "Date" ), TRUE );
To update the forms visually you need to create an Frm_Update_Line function in the SubForm.
You can than call this form the header form like:
CurrForm.MysubFormCtrl.FORM.Frm_Update()
You can optionally pass a parameter to be able to try saving the values.
NB! Avoid giving the Update functions in the form and in the table the same name as the header form might trigger the line table function
Cheers0
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