202 Lotus blogs updated hourly. Who will post next? Home | Blogs | Search | About 
Latest 7 Posts
Domino 10 and Beyond – my thoughts
Sun, Dec 3rd 2017 76
IBM Bluemix is now IBM Cloud
Sun, Dec 3rd 2017 33
ICON UK – Webinar about IBM’s Domino 10 and HCL partnership
Wed, Nov 8th 2017 5
Nominate your Champion(s)!
Tue, Nov 7th 2017 6
Who wants to live forever? IBM Notes and Domino!
Wed, Oct 25th 2017 9
Rebuilding my Domino infrastucture
Tue, Oct 24th 2017 5
IBM Watson Workspace is available – and it is free
Thu, Sep 28th 2017 7
Top 10
Domino 10 and Beyond – my thoughts
Sun, Dec 3rd 2017 76
IBM Bluemix is now IBM Cloud
Sun, Dec 3rd 2017 33
File Upload in Classic Domino Web using jQuery and Bootstrap
Thu, Jan 8th 2015 12
Code snippet – jQuery
Sat, Mar 15th 2014 10
IBM Connect 2017 – It’s that time of the year!
Mon, Dec 5th 2016 10
IBM Connect 2017 – I will be speaking in San Francisco
Tue, Jan 3rd 2017 9
Who wants to live forever? IBM Notes and Domino!
Wed, Oct 25th 2017 9
How to get the upcoming Font Awesome Pro 5.0 for $20
Sun, Oct 30th 2016 8
MWLUG in Austin – I will be presenting again
Mon, Jun 27th 2016 7
IBM Connect 2017 – My Session
Fri, Feb 17th 2017 7

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
11 hits

Recent Blog Posts
Domino 10 and Beyond – my thoughts
Sun, Dec 3rd 2017 11:43p   Karl-Henry Martinsson
It has now been a little over a month since IBM announced the new direction of IBM Notes, Domino, Verse and Sametime. I have been thinking through what I think this means for the product and the ecosystem of third-party tools and business partners. Some people view the move of development from IBM to HCL […]
IBM Bluemix is now IBM Cloud
Sun, Dec 3rd 2017 9:56p   Karl-Henry Martinsson
IBM recently renamed IBM Bluemix, their PaaS (Platform as a Service) offering, to IBM Cloud. This new name makes more sense, and much better describes what it is. From a marketing view, this is a good change. From a technical point, nothing changes. You still have a huge amount of different services and API:s to […]
ICON UK – Webinar about IBM’s Domino 10 and HCL partnership
Wed, Nov 8th 2017 2:53p   Karl-Henry Martinsson
On November 9 at 15.00 BST (10.00 CET, 10am EST), ICON UK will host a special edition of their “Around The Table” webinar series focusing on the recently announced strategic partnership between IBM and HCL. The partnership, which covers the Notes, Domino, Verse and Sametime product families, will deliver a multi-year roadmap for the products, […]
Nominate your Champion(s)!
Tue, Nov 7th 2017 4:55a   Karl-Henry Martinsson
It this time of the year again: nominations for IBM Champions! Do you know someone in the community that deserves the title of IBM Champion? Someone who demonstrates both expertise and extraordinary support and advocacy for IBM products, solutions and communities. Perhaps someone who arranges user conferences, create videos to show different concepts, blog and […]
Who wants to live forever? IBM Notes and Domino!
Wed, Oct 25th 2017 6:07p   Karl-Henry Martinsson
We have heard people claiming for years that Notes and Domino is dead. Today IBM announced a move that should put those statements to a stop. IBM is partnering with HCL Technologies on the future development of IBM Notes and Domino, as well as SameTime, Verse, Traveler and the other associated products. The products will […]
Rebuilding my Domino infrastucture
Tue, Oct 24th 2017 6:25a   Karl-Henry Martinsson
Recently I did some long overdue changes to my Domino infrastucture. Many years ago, when I initially setup my Domino server, I put it in the domain /Martinsson, since my domain at that time was martinsson.com (as well as martinsson.net). The server was just for practice and fun initially, but I ended up doing more […]
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 […]

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