Options

Pass FieldRef as Parameter to use in UPDATEALL

EdZEdZ 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

Answers

  • Options
    EdZEdZ Member Posts: 10
    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

    Cheers
Sign In or Register to comment.