Storing Tokens in NAV and reading into text

robbonickrobbonick Member Posts: 40
Hi Everyone, I am just looking for some advice on the issue of storing tokens for authentication in NAV.
We currently have a requirement which means we need to store a token, in our NAV DB so it can be easily changed through a page.

The issue is this token can be quite large in size, so a 250 character size text field will not cover it.
So naturally, the next thing I looked into was storing it in a Blob field.

I have created a function which will write the input into the blob field, and a function to return this blob as a text variable.
My function returns a text variable which doesn't have a defined length. So I would assume it can handle a much larger token than I am giving it.

The issue I am seeing is that when I debug, I don't get the full length token... is this just a quirk of the debugger?
I am currently trying to test this outside of NAV, but thought I would ask the question in the mean time.

This is the code I am using to store the token, run from the page when a user changes the token
IF SubmissionToken <> OriginalToken THEN 
  IF CONFIRM(UpdateTokenQst) THEN BEGIN
    "Submission Token".CREATEOUTSTREAM(OutStr);
    BinaryWriter := BinaryWriter.BinaryWriter(OutStr);
    BinaryWriter.Write(SubmissionToken);
    BinaryWriter.Close;
    MODIFY;
  END;

and this is the function I am using to then return this as a text variable
GetTokenAsText() Token : Text
CALCFIELDS("Submission Token");
"Submission Token".CREATEINSTREAM(InStr);
BinaryReader := BinaryReader.BinaryReader(InStr);
IF NOT ISNULL(BinaryReader) THEN BEGIN
  IF BinaryReader.BaseStream.Length > 0 THEN
    Token := BinaryReader.ReadString;
   BinaryReader.Close;
   EXIT(Token);
END;

I am just wondering if there is a better way to do this?


Best Answer

Answers

  • robbonickrobbonick Member Posts: 40
    Thanks Slawek_Guzek, I have updated my code to use the TempBlob functionality. Thanks for the recommendation. I wonder if the debugger in VSCode will have this same bug of clipping long text...
Sign In or Register to comment.