NAV 2016 - Updating Notes from in Record Link table

Hi Folks -

I have a txt file named Newfilename.txt which 240 character of text something like this just 1 line in the file.

Customer no : 20000 Credit Limit : 10000 Tax area code : VA Date - 04/12/18 Location Code : 001 Department Code : 01

I am trying to write this to the Record link Notes table and I don’t get any errors but the issue is that the entire text is not shown in the Notes it shows something like the below

Customer no : 20000 Credit Limit : 10000 Tax area code : VA

It drops the remaining text.

RecordLink.Note.CREATEOUTSTREAM(StreamOutObj);

MyFile.WRITEMODE(FALSE);
MyFile.TEXTMODE(TRUE);
MyFile.OPEN(NewFileName);
MyFile.CREATEINSTREAM(StreamInObj);

IntLen := MyFile.LEN;
WHILE (MyFile.POS < IntLen) DO BEGIN
    MyFile.READ(s);
    StreamInObj.READTEXT(s);
    StreamOutObj.WRITETEXT(s,MAXSTRLEN(s));
END;

MyFile.CLOSE();

Does anyone know what could the issue with the above function.

Any help is highly appreciated.

Thanks

Hi SBhatBng,

Why are you trying to read/write, why not just use COPYSTREAM?

Hi Erik -

I tried copystream too, COPYSTREAM(outstream,INSTREAM) what happens is say I have a string

Customer no. : 0001 Location Code : L1 Division code : 1234 Tax Area code : R001 Cust. Disc. Group : A001, everything works just fine but when I go to the Notes it just shows

Customer no. : 0001 Location Code : L1 Division code : 1234 and the remaining part of Tax area code : R001 and Cust. Disc. Group : A0001 is not there. I am just lost as to what am I missing. I have been scratching my head to resolve this issue, as you know If I go to a customer card and enter notes, I can enter tons of notes but when you update notes through a code, it just restricts to certain characters, not sure why.

That’s strange, normally it takes the whole content. What is the code you are using with COPYSTREAM?

Don’t open the file in writemode, if that doesn’t work try without textmode (you just want to copy the whole content right?).

Hi Erik -

I tried your way too and still not luck. Below is the code for this task. Some code is remmed trying out all possible ways to get this working. Really…Really strange. Thanks again for all your help Erik.

In NewfileName which is called custinfo.txt below is the content

Customer no. : 0001 Location Code : L1 Division code : 1234 Tax Area code : R001 Cust. Disc. Group : A001

IF FileMgt.ServerFileExists(NewFileName) THEN BEGIN

RecRef.GETTABLE(CustRec);
RecordLink.RESET;
IF RecordLink.FIND(’+’) THEN
LinkNo := RecordLink.“Link ID” + 1
ELSE
LinkNo := 1;

RecordLink.RESET;
RecordLink.INIT;
RecordLink.“Link ID” := LinkNo;
RecordLink.“Record ID” := RecRef.RECORDID;
RecordLink.URL1 := GETURL(CLIENTTYPE::Current, COMPANYNAME, OBJECTTYPE::Page, PAGE::“Customer Card”);
RecordLink.Type := RecordLink.Type::Note;
RecordLink.Created := CURRENTDATETIME;
RecordLink.“User ID”:=USERID;
RecordLink.“To User ID” := GLSetup.“CFO Email-ID”;
RecordLink.Company:=COMPANYNAME;
RecordLink.Notify := TRUE;
NewFunction(RecordLink);
RecordLink.INSERT;
END;

LOCAL NewFunction(VAR RecordLink : Record “Record Link”)
RecordLink.Note.CREATEOUTSTREAM(StreamOutObj);

//MyFile.WRITEMODE(FALSE);
//MyFile.TEXTMODE(TRUE);
MyFile.OPEN(NewFileName);
MyFile.CREATEINSTREAM(StreamInObj);

IntLen := MyFile.LEN;
//WHILE (MyFile.POS < IntLen) DO BEGIN
//MyFile.READ(s);
StreamInObj.READ(s,MAXSTRLEN(s));
//COPYSTREAM(StreamOutObj,StreamInObj);
StreamOutObj.WRITE(s,MAXSTRLEN(s));
//StreamInObj.READTEXT(s);
//StreamOutObj.WRITETEXT(s,MAXSTRLEN(s));
//END;

MyFile.CLOSE();

Is this the code you tested? The why do you have // before copystream?

You also have no create outstream!

This example is from Microsoft’s own doc page. It copies a file to a file, but the principle is the same.

F1.OPEN('c:\Test.txt');  
F1.CREATEINSTREAM(InS);  
F2.CREATE('c:\CopyTest.txt');  
F2.CREATEOUTSTREAM(OutS);  
COPYSTREAM(OutS,InS);  
F1.CLOSE();  
F2.CLOSE();  

Hi Erik -

Thanks for your reply. Createoutstream is at the beginning of the function

RecordLink.Note.CREATEOUTSTREAM(StreamOutObj);

Even I have seen the above code from Microsoft doc page and copying from file to file is not an issue works perfectly and I agree with you that the principle is the same but unfortunately it’s not when it comes to copying from a file to the Notes of the record link. There is some character restriction when you copy the text from a file to Notes in the record link table.

Thanks again for all your help.

You are not supposed to use READ / WRITE.

Ok, agreed I will not use READ / WRITE, so the below should work correct or let me know if I am missing out something. Since I am writing to the Notes of record link. I have to use the createoutstream on record link. Still does not work. Chops off half of my text.

MyFile.OPEN(NewFileName);
MyFile.CREATEINSTREAM(StreamInObj);
RecordLink.Note.CREATEOUTSTREAM(StreamOutObj);
COPYSTREAM(StreamOutObj,StreamInObj);
MyFile.CLOSE();

Strange. You’re sure that the file doesn’t contain any controls to break it? And you remember to save the record link record?

Hi Erik - Really strange, I have tried just by creating a single line text in a file without any controls or break and in the record link I have INSERT command and like I said it’s creating the text in the Notes of record link but not the entire text, if your text has 290 characters, In notes it just shows 140 characters of the text.

Having worked with NAV for the last 26 years, this is the first time NAV has stumped me. I have worked with Nav Since Avista till today’s version and I have resolved any issues but this one issue just beats me.

I’ve never seen this before either. I have worked with the notes before, and never had a problem. Not via a file import but via a function where I just insert the text:

PROCEDURE SetText(Notification : Text[1000];VAR RecordLink : Record "Record Link")
c1 := 13;
lf[1] := c1;

s := Notification;

SystemUTF8Encoder := SystemUTF8Encoder.UTF8Encoding;
SystemByteArray := SystemUTF8Encoder.GetBytes(s);

RecordLink.Note.CREATEOUTSTREAM(OStr);
x := SystemByteArray.Length DIV 128;
IF x > 1 THEN
  y := SystemByteArray.Length - 128 * (x - 1)
ELSE
  y := SystemByteArray.Length;
c1 := y;
OStr.WRITE(c1);
IF x > 0 THEN BEGIN
  c2 := x;
  OStr.WRITE(c2);
END;
FOR i := 0 TO SystemByteArray.Length - 1 DO BEGIN
  c1 := SystemByteArray.GetValue(i);
  OStr.WRITE(c1);
END;

As you see, then I’m also setting some dotnet vars (mscorlib/System.Text.UTF8Encoding and mscorlib/System.Array). This is something I did for NAV 2009, but assume it works in NAV 2016.

Hi Erik - This function Settext is in NAV 2016 Codeunit 454 Job Queue - Send Notification. I initially took the same function and tried and was so confident that it will work and as I said it did work but when it chopped of the notes that’s when I realized something is not right, then like you suggested I tried COPYSTREAM and I tried READ, WRITE and all sort of functions but no luck. When you debug you will see that the entire string in the instream but as soon as it writes it into Notes of Recordlink that’s where it fails. I am not sure if there is some kind of restriction/limit in Notes to update values from file, really…really strange and I am working on this issue and will update the forum if I find a solution.

Thanks Erik for all your help.

Well yes it may come from there. I knew I would never have named variable myself that way. But try with it, even if you have to read your file into a text string first.

Not really sure why it’s so complex to put data in there, but it’s obvious not a normal blob field.