Dataport to update table fields

asemberengasembereng Member Posts: 220
I created a dataport to update table fields but its not updating but instead writes a new record and increment the previous primary key by 1. Can someone help me? both AutoSave and Autoupdate is set to Yes. I dont know what i am doing wrong. Thanks

Comments

  • asemberengasembereng Member Posts: 220
    I think its updating now. I just set the transaction to UPDATE. need to test it further. Anyway better way of doing it?
  • krikikriki Member, Moderator Posts: 9,110
    Are you sure your dataport contains also the primary key fields?
    You need these to get the record and then to update it.



    In general I would import the data into the fields of a table I DON'T save.
    In the OnAfterImportRecord-trigger, I put some C/AL code to get the record, change the fields and to modify it.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • asemberengasembereng Member Posts: 220
    I am getting the primary key. Can you give me an example using the employee table if using the c/al option?
  • krikikriki Member, Moderator Posts: 9,110
    The dataItem is "Employee".
    -Properties
    AutoSave,AutoUpdate,AutoReplace=no

    In the "OnBeforeImportRecord()"-trigger, you must clear all the variables in your dataitemfields. If it are only fields of the dataitem-record, a CLEAR of it is enough:
    CLEAR(Employee);
    

    In the OnAfterImportRecord()-trigger: (you need to define a new global "recEmployee" as type Record:Employee
    recEmployee.GET("No.");
    recEmployee.VALIDATE("Field 1","Field 1");
    recEmployee."Field 2" := "Field 2";
    recEmployee.VALIDATE("Field 3","Field 3");
    recEmployee."Field 4" := "Field 4";
    recEmployee.MODIFY(TRUE);
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • asemberengasembereng Member Posts: 220
    Using comma to separate my fields, will recognize the first value before the comma as field 1 and next as field 2?
    Thanks
  • krikikriki Member, Moderator Posts: 9,110
    asembereng wrote:
    Using comma to separate my fields, will recognize the first value before the comma as field 1 and next as field 2?
    Thanks
    yes, but it is better to use tab-separated files.

    In the Dataport-properties you must put (you need also to put the < and the > ; the characters must be EXACTLY is I wrote):
    FieldSeparator=<TAB>
    FieldStartDelimiter,FieldEndDelimiter=<None>
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • asemberengasembereng Member Posts: 220
    thank you. I will give it a try right away.
Sign In or Register to comment.