How to copy Notes (stored in Record Links table)

AtreiuAtreiu Member Posts: 51
edited 2010-04-19 in NAV Three Tier
Hi everybody,
I'm getting crazy with this...

Example:
In the RTC client I add a note to the Sales Order #100. The program write it in the Record Links table and the only way to know that my Sales Order 100 has a note is to read the field "RecordID" in the Record Links table.
The Sales Header has no link field like that...

When I post my order, I want to copy the note in the Shipment (and then in the Invoice). I cannot do this.

I've tried to filter Record Links table, but it's not possible to use "Record ID" to filter (I cannot compare a RECORDID data type to a text type, and it's not possible to convert the text into RECORDID). I also cannot write another text field where to copy the value from Record ID...

any suggestion?

thanks...

Comments

  • kinekine Member Posts: 12,562
    I am not sure, but cannot you use the "HASLINKS", "COPYLINKS" etc. command to work with the notes like with any other links?
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • ufukufuk Member Posts: 514
    You can use copylinks as Kine said and you can also apply filters like:
    RecLink.SETFILTER("Record ID",FORMAT(prec."Record ID"));
    
    or
    RecLink.SETFILTER("Record ID",SalesHeader.TABLENAME+': '+FORMAT(SalesHeader."Document Type")+','+SalesHeader."No.");
    
    Ufuk Asci
    Pargesoft
  • AtreiuAtreiu Member Posts: 51
    Ok, being a newbie, I'm going with baby steps...

    There's a line of the Record Link table which "Record ID" field is Purch. Rcpt. Header: 10-0010.

    First test:
    RecordLink.SETFILTER("Record ID",'Purch. Rcpt. Header: 10-0010');
    IF RecordLink.FINDSET(TRUE) THEN
    MESSAGE('Record ID %1',RecordLink."Link ID");
    
    and it returns the right value.

    Second test:
    I put this code in the codeunit 333 and tried to copy the links to the purchase order, but it did not work.
    PurchOrderHeader.COPYLINKS(RecordLink);
    

    Third test:
    I tried to copy this record to a new one on the same table, changing 2 fields:
    RecordLink.INIT;
    RecordLink.TRANSFERFIELDS(RecordLink);
    RecordLink."Link ID" := 71;
    RecordLink."Record ID" :='Purchase Header: Ordine,10-0562';
    RecordLink.INSERT;
    

    I get the usual error "invalid type" RecordID := Text.



    (in the classic client there are no notes, so I can't use the debugger... does anybody have any idea about how navision create records in the Record Links table? I've found no Codeunit doing that, for example...)
  • AlishaAlisha Member Posts: 217
    I did this code that copies Notes from one Customer to another, using RecordRef, maybe you can use it to copy the note to another table:


    CALCFIELDS(Note);
    NewRecLink.INIT;
    NewRecLink.TRANSFERFIELDS("Record Link");
    NewRecLink."Link ID" := entryNo;
    entryNo +=1;

    NewRecRef.OPEN(18);
    NewRecRef.GETTABLE(NewCust);
    NewRecLink."Record ID" := NewRecRef.RECORDID;

    NewRecLink.INSERT;
    NewRecRef.CLOSE;

    NewCust is a record variable that contains the new customer, "Record Link" contains the current Note for the current customer.
  • AtreiuAtreiu Member Posts: 51
    Hi everybody
    I got it!
    Thanks to all!!! You're great. =D>


    This is the explanation of what I've done (for other ignorant people like me...).
    And maybe the experts can "validate it" :) or tell me if it could be even better (or something useless I've written)... (and let me know how to mark this topic as 'solved')

    General information:
    - copy from a Requisition request to a Purchase order.
    - CodeUnit 333 - Req. Wksh.-Make Order

    Global variables:
    [Name DataType Subtype Length]
    RecordLink Record Record Link
    NewRecLink Record Record Link
    NewRecRef RecordRef
    NewOrder Record Purchase Header
    MaxLinkID Integer
    LinkID Integer

    I created the function CopyRecordLinks with the local parameter:
    Var Name DataType Subtype Length
    Sì ReqLine Record Requisition Line

    and it is called in the CarryOutReqLineAction function, when the action message is "new".
    //Calcolo il massimo Link ID utilizzato nella tabella Record Links
    REPEAT
    LinkID := RecordLink."Link ID";
    IF LinkID > MaxLinkID THEN
    MaxLinkID := LinkID
    UNTIL  RecordLink.NEXT = 0;
    
    //Filtro tutti i link relativi alla mia richiesta d'approv.
    RecordLink.SETFILTER("Record ID",'Requisition Line: RICH.,DEFAULT,'+FORMAT(ReqLine."Line No."));
    
    //Se trovo dei link vado a copiarli nell'ordine d'acquisto
    IF RecordLink.FINDSET(TRUE) THEN BEGIN
          REPEAT
             RecordLink.CALCFIELDS(Note);
             //Copio il record 
             NewRecLink.INIT;
             NewRecLink.TRANSFERFIELDS(RecordLink);
             NewRecLink."Link ID" := MaxLinkID+1;
    
             //Creo una variabile 'record' con il numero dell'ordine di acquisto creato
             NewOrder.INIT;
             NewOrder.GET(NewOrder."Document Type"::Order,PurchOrderHeader."No.");
    
             //Faccio riferimento alla variabile dell'ordine e creo un nuovo link con quel riferimento
             NewRecRef.OPEN(38);
             NewRecRef.GETTABLE(NewOrder);
             NewRecLink."Record ID" := NewRecRef.RECORDID;
             NewRecLink.INSERT;
             NewRecRef.CLOSE;
             //Aumento il contatore per il prossimo eventuale record
             MaxLinkID += 1;
          UNTIL  RecordLink.NEXT = 0;
    END;
    COMMIT;
    

    Some questions:
    1) could I improve this part
    RecordLink.SETFILTER("Record ID",'RequisitionLineRequisition Line: RICH.,DEFAULT,'+FORMAT(ReqLine."Line No."));
    writing something similar to this (copied from another discussion):
    IF PurchaseHeader.HASLINKS THEN
    BEGIN
      RecRef.OPEN(DATABASE::"Purchase Header");
      RecRef.GETTABLE(PurchaseHeader);
      PurchHeaderRecordID := RecRef.RECORDID;
      RecordLink.SETRANGE(RecordLink."Record ID",PurchHeaderRecordID);
      IF RecordLink.FINDSET THEN
      REPEAT
        MESSAGE(RecordLink.URL1);
      UNTIL RecordLink.NEXT = 0;
    END;
    
    ?
    (note that the batch should always be 'DEFAULT', but this is not granted...)

    2) why is this linke necessary:
    RecordLink.CALCFIELDS(Note);
    ?
  • DoomhammerDoomhammer Member Posts: 211
    Hi folks, thank you for nice recordref walkthrough :smile:
    Martin Bokůvka, AxiomProvis
  • philippegirodphilippegirod Member Posts: 191
    Hi all,

    Question : when I use this copy code, in case of a Record link Type = Note, the URL is completely wrong (the link is with the original link record, not the new one), do you know how to correct that?

    For instance, I wanted to copy the Records Links after copy of the Customer records from a company to another (in new company, customers have new No. :
    RecRef.OPEN(18);
          RecRef.GETTABLE(Source_18_Customer);
          SourceRecordID := RecRef.RECORDID;
          RecRef.CLOSE;
          
          Dest_2000000068_RecordLink.RESET;
          Dest_2000000068_RecordLink.FINDLAST;
          IDLink := Dest_2000000068_RecordLink."Link ID";
          Source_2000000068_RecordLink.SETFILTER("Record ID",'%1',SourceRecordID);
          Source_2000000068_RecordLink.SETFILTER(Company,Company.Name);
          IF Source_2000000068_RecordLink.FINDSET THEN REPEAT
            IF Source_2000000068_RecordLink.CALCFIELDS(Note);
            IDLink := IDLink +10;
            RecRef.OPEN(18);
            RecRef.GETTABLE(Dest_18_Customer);
            Dest_2000000068_RecordLink.INIT;
              Dest_2000000068_RecordLink.TRANSFERFIELDS(Source_2000000068_RecordLink);
              Dest_2000000068_RecordLink."Link ID" := IDLink;
              Dest_2000000068_RecordLink."Record ID" := RecRef.RECORDID;
              RecRef.GET
              Dest_2000000068_RecordLink.Company := COMPANYNAME;
            Dest_2000000068_RecordLink.INSERT;
            RecRef.CLOSE;
          UNTIL Source_2000000068_RecordLink.NEXT = 0;
    


    My candle burns by both ends, it will not last the night,
    But oh my foes and oh my friends, it gives a lovely light
  • vaprogvaprog Member Posts: 1,144
    What do you mean by "the URL is completely wrong"?

    The fileds "URL 1" .. "URL 4" are text fields which are copied as is. They are concatenated to construct the full URL shown in the Links InfoBox. The URL is ment to point anywhere you like. So, an auto-update is out of question. The "Record ID" field is what points to the record the note is attached to.

    Note that "Link ID" is an AutoIncrement field. You should set it to 0. Any other value re-initializes the Auto Increment value on the SQL Table. This costs performance and possibly causes problems when trying to insert a new record doing it as intended (i.e. from the default InfoBoxes).

    You do not need to use a RecordRef to get a Record ID, a record has had a RECORDID property for many version now.

    As a rule you should not use TRANSFERFIELDS to copy fields from one record to another of the same type. Just assign the record.

    I am not sure about this, but I would guess that COPYLINKS copies Links and Notes. In fact @kine suggested this above and @ufuk confirmed it.
Sign In or Register to comment.