RecRef and FieldRef

Matt_KeyesMatt_Keyes Member Posts: 23
I am having zero luck updating a new record from a recref via a field ref.

Like so:

      UpdateBuffer.SETRANGE("Primary Key",TRUE);
      IF NOT UpdateBuffer.FINDFIRST THEN
        ERROR(STRSUBSTNO('No primary keys found for table %1.',UpdateBuffer."Table No."));

      RecRef.OPEN(UpdateBuffer."Table No.",FALSE,COMPANYNAME);
      RecRef.INIT;

      REPEAT
        FieldRef := RecRef.FIELD(UpdateBuffer."Field No.");
        EVALUATE("Var",UpdateBuffer."Field Value");
        FieldRef.VALIDATE("Var");
      UNTIL UpdateBuffer.NEXT = 0;

      UpdateBuffer.SETRANGE("Primary Key",FALSE);

      IF UpdateBuffer.FINDFIRST THEN REPEAT
        //now get each field ref and set the value accordingly
        FieldRef := RecRef.FIELD(UpdateBuffer."Field No.");
        EVALUATE("Var",UpdateBuffer."Field Value");
        FieldRef.VALIDATE("Var");
      UNTIL UpdateBuffer.NEXT = 0;

      //call a modify here on the rec ref
      RecRef.INSERT(TRUE);
      RecRef.CLOSE;


A record is indeed inserted but none of the values from the fieldref validate calls are set. Any advice?

Comments

  • DaveTDaveT Member Posts: 1,039
    Hi Matt,

    Not sure what you are trying to acheive with the code. I'm guessing the you are hoping to update a number of records but "recref" variable is on the initial record. There is not MODIFY and only one INSERT. On the face of it, I think you are over complicating it. A second UpdateBuffer would be more normal.

    Can you explain what you want to acheive
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
Sign In or Register to comment.