198 Lotus blogs updated hourly. Who will post next? Home | Blogs | Search | About 
Latest 7 Posts
IBM Watson Workspace is available – and it is free
Thu, Sep 28th 2017 3
My MWLUG presentation: Elementary!
Wed, Aug 9th 2017 2
My presentation at MWLUG
Tue, Aug 8th 2017 2
Will I see you at MWLUG?
Thu, Jul 27th 2017 6
A few openings left for MWLUG 2017 
Mon, Jul 17th 2017 2
Load and Modify External File in NetSuite
Fri, Jul 7th 2017 4
MWLUG 2017 – Be There!
Fri, Jul 7th 2017 6
Top 10
Code snippet – jQuery
Sat, Mar 15th 2014 12
File Upload in Classic Domino Web using jQuery and Bootstrap
Thu, Jan 8th 2015 9
My Connect 2016 presentation & demo database
Wed, Feb 17th 2016 9
My MWLUG presentation
Fri, Sep 2nd 2016 7
IBM Connect 2017 – It’s that time of the year!
Mon, Dec 5th 2016 7
Two more days to thank someone
Mon, Sep 15th 2014 6
Some upcoming conferences
Mon, Mar 14th 2016 6
How to get the upcoming Font Awesome Pro 5.0 for $20
Sun, Oct 30th 2016 6
IBM Connect 2017 – I will be speaking in San Francisco
Tue, Jan 3rd 2017 6
MWLUG 2017 – Be There!
Fri, Jul 7th 2017 6

Code snippet – jQuery
Twitter Google+ Facebook LinkedIn Addthis Email Gmail Flipboard Reddit Tumblr WhatsApp StumbleUpon Yammer Evernote Delicious
Karl-Henry Martinsson    

This morning I was working on a web application, and I came up with a pretty neat and simple little solution. So I just wanted to share it, in case anyone else need something similar.

I have a webpage with an HTML form. Each input tag has an attribute called notesfield, matching the name of the field in Notes where the value is stored:

<div class="col-md-3">
    <label>First Name</label>
    <input class="form-control" type="text" notesfield="FirstName" value="" />
<div class="col-md-2">
    <input class="form-control" type="text" notesfield="MiddleInitial" value="" />
<div class="col-md-3">
    <label>Last Name</label>
    <input class="form-control" type="text" notesfield="LastName" value="" />

Then I created a simple function that will call an agent on the Domino server, which will return all the fields on the specified document as JSON. This function is called after the HTML page is fully loaded.

function loadNotesFields(docunid) {
	var notesfieldname = "";
		url: "/database.nsf/ajax_GetNotesFieldFields?OpenAgent", 
		data: {"NotesUNID":docunid},
		cache: false
	}).done(function(data) {
		$('input[notesfield]').each(function() {
			notesfieldname = $(this).attr("notesfield");

The function is actually extremely simple, and here you can see the power of jQuery. What I do is to perform an Ajax call to a Domino URL, passing a UNID to the agent to use in the lookup. I set cache to false, to avoid the browser from reusing previously retrieved data (this is a good thing to do if the data retrieved can be suspected to change frequently).

The jQuery .ajax() functions returns the JSON in the data object, and when the call is done, the callback function loops through each input element with an attribute of notesfield, reads the value of said attribute and then sets the value of the input element to the corresponding Notes value.

The only thing left is to write the agent that will return the JSON. It could look something like this:

Dim urldata List As String

Sub Initialize
	Dim session As New NotesSession
	Dim webform As NotesDocument
	Dim db As NotesDatabase
	Dim doc As NotesDocument
	Dim urlstring As String
	Dim urlarr As Variant
	Dim urlvaluename As Variant
	Dim i As Integer
	Dim json As String

	Set webform = session.DocumentContext
	'*** Remove leading "OpenAgent" from Query_String
	urlstring = StrRight(webform.Query_String_Decoded(0),"&")
	'*** Create list of arguments passed to agent
	urlarr = Split(urlstring,"&")
	For i = LBound(urlarr) To UBound(urlarr)
		urlvaluename = Split(urlarr(i),"=")
		urldata(urlvaluename(0)) = urlvaluename(1)
	Set thisdb = session.CurrentDatabase
	'*** Create content header for return data
	Print "content-type: application/json"
	'*** Get Notes document baed on NotesUIND argument
	Set doc = db.GetDocumentByUNID(urldata("NotesUNID"))
	'*** Build JSON for all fields in document except $fields
	json = "{" + Chr$(13)
	ForAll item In doc.Items
		If Left$(item.Name,1)<>"$" Then
			json = json + |"| + item.Name + |":"| + item.Text + |",|+ Chr$(13)
		End If
	End ForAll
	'*** Remove trailing comma and line break
	json = Left$(json,Len(json)-2)	
	json = json + "}"
	'*** Return JSON
	Print json	
End Sub

Happy coding!

Mar 15, 2014
13 hits

Recent Blog Posts
IBM Watson Workspace is available – and it is free
Thu, Sep 28th 2017 2:50a   Karl-Henry Martinsson
Yesterday IBM formally launched Watson Workspace as a general availability product. Anyone can now sign up for the free version, previously you needed an invitation. But the interesting part is the enterprise version Workspace Essentials, with features for security and control needed in that kind of environment. There you can also create and manage guest […]
My MWLUG presentation: Elementary!
Wed, Aug 9th 2017 3:27p   Karl-Henry Martinsson
Yesterday I presented at MWLUG, and I want to share my presentation with both the ones attending and anyone who was not able to be there. I am posting two version, one with just the slides, and one with speaker notes, where I tried to capture the content, if not the exact verbiage of the […]
My presentation at MWLUG
Tue, Aug 8th 2017 5:33a   Karl-Henry Martinsson
Tomorrow, August 8, you are welcome to attend my presentation “Elementary!” at MWLUG 2017. In about 45 minutes I will show how to easily incorporate Watson functionality in your own applications, both on the web and in your Notes client applications. I will be using Node-RED and IBM BlueMix to do this, and I think […]
Will I see you at MWLUG?
Thu, Jul 27th 2017 4:41p   Karl-Henry Martinsson
It is less than 2 weeks left to MWLUG 2017, an outstanding Conference that I will be attending for the third year. This will also be the third year I will be speaking, and this time it will be a brand new presentation. My session, AD103, will be on Tuesday, Auguts 8 at 5pm. I […]
A few openings left for MWLUG 2017 
Mon, Jul 17th 2017 10:34p   Karl-Henry Martinsson
There are a a few openings available for MWLUG in a couple of weeks. The conference is taking place August 8-10 in Alexandria, VA. It is shaping up to be a great experience, with over 50 sessions, two free workshops  as well as social events and two round table discussions with IBM on the future of development. Among the many great […]
Load and Modify External File in NetSuite
Fri, Jul 7th 2017 7:00p   Karl-Henry Martinsson
When building a suitelet in NetSuite you can either inject HTML, CSS and Javascript in a field, or generate a full HTML page and render it into the suitelet. No matter which method you use, you normally have to write line after line of SuiteScript code where you build the HTML using string concatenation. This […]
MWLUG 2017 – Be There!
Fri, Jul 7th 2017 2:52a   Karl-Henry Martinsson
This year’s MWLUG conference will take place in Alexandria, VA. During the three day conference more than 50 sessions and two free workshops will be offered. All this for just $75. This year the conference starts a day earlier than usual, on a Tuesday. But everything you are used to from the previous years will […]
Easy NetSuite Search
Thu, Jul 6th 2017 3:07a   Karl-Henry Martinsson
In an attempt to expand my knowledge to other platforms than Notes and Domino, I have now been working with NetSuite for a number of months. I have mainly been working with the ERP part of the cloud based system. The language used is called SuiteScript, and it is Javascript with a NetSuite-specific API to […]
My Connect 2017 demo code
Tue, Jul 4th 2017 3:46p   Karl-Henry Martinsson
The demo database from my presentation at IBM Connect 2017 is finally available. It contains the code from The Great Code Giveaway as well as the bonus application for version management. Don’t forget to sign the databases with an ID that has rights to run agents on the server.  
More time for your MWLUG abstract submission
Mon, May 29th 2017 3:36a   Karl-Henry Martinsson
Richard Moy, organizer of MWLUG, has extended the deadline for submission of abstract submission another week, until Friday, June 2. So if you haven’t gotten around to submit an abstract yet, you have a few more days to come up with a good subject to present at this years MWLUG conference, taking place on August 8-10 in Washington, […]

Created and Maintained by Yancy Lent - About - Planet Lotus Blog - Advertising - Mobile Edition