Domino JSON Test

Embedded in this page is the result of a Domino 7.0.2 OutptFormat=JSON URL Command (stripped down to only include 5 documents with 2 columns). Using a basic script I'm seeing how versatile it is.

Let's see if we can recreate a view-like table using this JSON. If you see a table below then it's worked.

Domino View

Note that column titles and widths are based on the back-end view design as is the alternate row colour.

The Code

The table is built using the following code:

var documents = view["data"].viewentry;
var columns = view["design"].column;

document.write("<p>Showing documents " + documents[0]["@position"]+
	" to " + documents[documents.length-1]["@position"] +
	" of " + view["@toplevelentries"]+"</p>");

document.write("<table border=\"1\" cellspacing=0 padding=4><tr>");
for(var i=0; i<columns.length; i++){
	document.write("<th style=\"width:"+(columns[i]["@width"]*10)
	+"px\">"+columns[i]["@title"]+"");
}
document.write("</tr>");

for(var i=0; i<documents.length; i++){
	document.write( "<tr"+((i%2==1)?" style=\"background-color:"
	+view["design"]["@altrowcolor"]+"\"":"")
	+"><td><a href=\"0/"+documents[i]["@unid"]+"?OpenDocument\">"
	+documents[i].entrydata[1].text[0]+
	""+documents[i].entrydata[0].text[0]
	+"</td></tr>");
}
document.write("</table>");

This code refers to the following JSON-style code, which is in Domino format. Normally this would be retrieved dynamically from the Domino server via an "AJAX" call to a ?ReadViewEntries&OutputFormat=JSON or ?ReadDesign&OutputFormat=JSON URL.

var view = new Array();

view["data"]={
	"@toplevelentries": 90212,
	viewentry: [
		{
			"@position": '1',
			"@unid": '240E2095BD938FA68525726E002ED6B7',
			"@noteid": '1334CA',
			"@siblings": 90212,
			entrydata: [ //column data
				{
					"@columnnumber": 0,
					"@name": '$129',
					text: {0: '25.Jan.07'}
				},
				{
					"@columnnumber": 1,
					"@name": '$126',
					text: {0: 'This is a test'}
				}
			] //end column data
		}, //end entry 1

		{
			"@position": '2',
			"@unid": '321562FD5499B5D88525726E002EB04A',
			"@noteid": '1334C2',
			"@siblings": 90212,
			entrydata: [
				{
					"@columnnumber": 0,
					"@name": '$129',
					text: {0: '25.Jan.07'}
				},
				{
					"@columnnumber": 1,
					"@name": '$126',
					text: {0: 'Me too'}
				}
			]
		},  //end entry 2
		{
			"@position": '3',
			"@unid": '3F62EE9FFE4439348525726E002DB3C4',
			"@noteid": '1334BA',
			"@siblings": 90212,
			entrydata: [
				{
					"@columnnumber": 0,
					"@name": '$129',
					text: {0: '25.Jan.07'}
				},
				{
					"@columnnumber": 1,
					"@name": '$126',
					text: {0: 'Hey, this works quite well'}
				}
			]
		} , //end entry 3
		{
			"@position": '4',
			"@unid": '3F42FE9FFE4439348525726E002DB3D2',
			"@noteid": '1334BB',
			"@siblings": 90212,
			entrydata: [
				{
					"@columnnumber": 0,
					"@name": '$129',
					text: {0: '21.Jan.07'}
				},
				{
					"@columnnumber": 1,
					"@name": '$126',
					text: {0: 'This has made my day'}
				}
			]
		}, //end entry 4
			{
				"@position": '5',
				"@unid": '2B4EEE9FFE4439348525726E002DB3F1',
				"@noteid": '1334BA',
				"@siblings": 90212,
				entrydata: [
					{
						"@columnnumber": 0,
						"@name": '$129',
						text: {0: '21.Jan.07'}
					},
					{
						"@columnnumber": 1,
						"@name": '$126',
						text: {0: 'Whatever next? Men on mars!?'}
					}
				]
		} //end entry 5
	] //end viewenry(s)
} //end JSON

view["design"]={
	"@rowlines": 9,
	"@direction": 0,
	"@spacing": 1,
	"@columns": 5,
	"@totalscolor": '#0000ff',
	"@altrowcolor": '#eee',
	column: [
			{
				"@columnnumber": 0,
				"@width": 64,
				"@name": '$129',
				"@title": 'Title',
				"@resize": 'true',
				"@format": 2,
				"@listseparator": 'none',
				cfont: {
					"@style": 'r',
					"@size": 7,
					"@color": '#000000',
					"@face": 'Helvetica'
				},
				hfont: {
					"@style": 'b',
					"@size": 7,
					"@color": '#000000',
					"@face": 'Helvetica'
				},
				numberformat: {
					"@digits": 1,
					"@format": 'general',
					"@varying": 'true'
				},
				datetimeformat: {
					"@show": 'date',
					"@date": 'yearmonthday',
					"@time": 'hourminute',
					"@zone": 'never',
					"@year4digit": 'true'
				}
			}, //end column
			{
				"@columnnumber": 1,
				"@width": 16,
				"@name": '$126',
				"@title": 'Date',
				"@sort": 'true',
				"@sortdescending": 'true',
				"@resize": 'true',
				"@align": 2,
				"@format": 1,
				"@listseparator": 'none',
				cfont: {
					"@style": 'r',
					"@size": 7,
					"@color": '#0000ff',
					"@face": 'Helvetica'
				},
				hfont: {
					"@style": 'b',
					"@size": 7,
					"@color": '#000000',
					"@face": 'Helvetica'
				},
				numberformat: {
					"@digits": 0,
					"@format": 'general'
				},
				datetimeformat: {
					"@show": 'datetime',
					"@date": 'yearmonthday',
					"@time": 'hourminutesecond',
					"@zone": 'never'
				}
			}
	] //end column(s)
} //end design

For more information see codestore.net