Problem modifying table data

karstenrobert
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.
Karsten Frank
MCP - Dynamics NAV Developer

Comments

  • idiot
    idiot Member Posts: 651
    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 challenger
  • karstenrobert
    karstenrobert Member Posts: 27
    Thanks for your answer.

    But I tried that too. I rechecked it and sadly it does not work.

    Karsten.
    Karsten Frank
    MCP - Dynamics NAV Developer
  • Albertvh
    Albertvh Member Posts: 516
    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 :D
  • karstenrobert
    karstenrobert Member Posts: 27
    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 Developer
  • aari
    aari Member Posts: 7
    have you tried RENAME instead of modify ?
  • karstenrobert
    karstenrobert Member Posts: 27
    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 Developer
  • Mbad
    Mbad Member Posts: 344
    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"
  • karstenrobert
    karstenrobert Member Posts: 27
    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 Developer