Obtain JSON Data from Domino 12 with DQL (an easy way)

With Domino 12, we have a new class available (Notes)QueryResultsProcess with helps in the mix of differents results comes from diferent sources (not only DQL) even several NSFs! sending to the user as JSON or as a “special view” if we are in HCL Domino 12.0.1.

The use of this class in a classic web agent allow us to obtain the Domino data in a clean, easy way without any third-party libraries.

    'You know what this variables are for
    Dim s As New NotesSession
    Dim db As NotesDatabase
    Set db = s.Currentdatabase
    'It is mandatory to define the variable that will store the query
    Dim domQuery As NotesDominoQuery
    Set domQuery = db.Createdominoquery()	
    'Now, the NotesQueryResultsProcessor. 
    Dim nqr As NotesQueryResultsProcessor
    Set nqr = db.Createqueryresultsprocessor()
    'the search criteria...
    Call nqr.Adddominoquery(domQuery, "Price > 1000", "PriceMoreThan1000")
    'We can use a defined NotesDocumentCollection from a Notesdatabase.search, FullText Search, ...
    'Call nqr.Addcollection(col, "PriceMoreThan1000")
    'The huge addin of NotesQueryResultsProcessor class is the posibility of sorting the data.
    'We need to define the sorting colums, in addition to the remain columns which we want to see in the final JSON
    Call nqr.Addcolumn("Number", "Number", |@TextToNumber("Number")|, SORT_DESCENDING, False, False)
    Call nqr.Addcolumn("Price, "Price", |@TextToNumber("Price")|, SORT_UNORDERED, False, False)
    'we can use the "Stringify" method, available in NotesJSONNavigator class to pass the data
    Dim jsonNavigator As NotesJSONNavigator
    Set jsonNavigator = nqr.Executetojson()
    'Headers wich They help the browser to process the result
    Print |Content-Type: text/json|
    Print |Cache-Control: no-cache|
    Print jsonNavigator.Stringify()

We can go further and parametrize through a QueryString or use an XAgent to extend and/or integrate with a defined XPages library.

I must say, although this is an endpoint with returns JSON data, this is not a well-defined REST. If you want a canonical REST service, there are better ways to build it in top of Domino, or maybe go straight to it and use the brand new Domino REST API, available for the HCL Domino 12.0.1.

REST in Domino with Lotusscript and Agents: a little enhacement I will be speaking at Collabsphere 2021: "How to make a hackathon-winner HCL Domino Volt application"


Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now