Storing Tokens in NAV and reading into text

robbonick
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
and this is the function I am using to then return this as a text variable
I am just wondering if there is a better way to do this?
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?
0
Best Answer
-
Yep, that's debugger clipping long text.
For writting and reading text into BLOBs look into table 99008535 TempBLOB, you will find WriteAsText and ReadAsText functions in thereCALCFIELDS("Submission Token"); TempBLOB.BLOB := "Submission Token"; TokenText := TempBLOB.ReadAsText(...)
Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-035
Answers
-
Yep, that's debugger clipping long text.
For writting and reading text into BLOBs look into table 99008535 TempBLOB, you will find WriteAsText and ReadAsText functions in thereCALCFIELDS("Submission Token"); TempBLOB.BLOB := "Submission Token"; TokenText := TempBLOB.ReadAsText(...)
Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-035 -
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...0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions