199 Lotus blogs updated hourly. Who will post next? Home | Blogs | Search | About 
 
Latest 7 Posts
My MWLUG presentation: Elementary!
Wed, Aug 9th 2017 15
My presentation at MWLUG
Tue, Aug 8th 2017 6
Will I see you at MWLUG?
Thu, Jul 27th 2017 5
A few openings left for MWLUG 2017 
Mon, Jul 17th 2017 4
Load and Modify External File in NetSuite
Fri, Jul 7th 2017 4
MWLUG 2017 – Be There!
Fri, Jul 7th 2017 9
Easy NetSuite Search
Thu, Jul 6th 2017 6
Top 10
My MWLUG presentation: Elementary!
Wed, Aug 9th 2017 15
More time for your MWLUG abstract submission
Mon, May 29th 2017 11
MWLUG 2017 – Be There!
Fri, Jul 7th 2017 9
Code snippet – jQuery
Sat, Mar 15th 2014 8
Save the date – IBM Connect 2017 announced!
Wed, Mar 23rd 2016 8
Blogging anniversary – 7 years!
Mon, Jan 19th 2015 7
MWLUG in Austin – I will be presenting again
Mon, Jun 27th 2016 7
File Upload in Classic Domino Web using jQuery and Bootstrap
Thu, Jan 8th 2015 6
Free Code – Clean groups in Domino Directory
Wed, Dec 16th 2015 6
Easy NetSuite Search
Thu, Jul 6th 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>
<div class="col-md-2">
    <label>Initial</label>
    <input class="form-control" type="text" notesfield="MiddleInitial" value="" />
</div>
<div class="col-md-3">
    <label>Last Name</label>
    <input class="form-control" type="text" notesfield="LastName" value="" />
</div>

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 = "";
	$.ajax({
		url: "/database.nsf/ajax_GetNotesFieldFields?OpenAgent", 
		data: {"NotesUNID":docunid},
		cache: false
	}).done(function(data) {
		$('input[notesfield]').each(function() {
			notesfieldname = $(this).attr("notesfield");
			$(this).val(data[notesfieldname]);
		});
	});
}

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)
	Next
	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!



---------------------
http://blog.texasswede.com/code-snippet-jquery/
Mar 15, 2014
9 hits



Recent Blog Posts
15
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 […]
6
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 […]
5
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 […]
4
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 […]
4
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 […]
9
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 […]
6
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 […]
1
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.  
11
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, […]
2
MWLUG Submssion Deadline
Wed, May 24th 2017 5:36a   Karl-Henry Martinsson
You have just over 3 days left to submit a session abstract for MWLUG 2017. The deadline is on Friday, May 26 at 5pm Central time. If you don’t want to speak, registration is also open to this excellent conference. This year it takes place August 8-10 at Hilton Mark Center in Alexandria, VA. Expect a […]




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