Showing posts with label Lotus Domino. Show all posts
Showing posts with label Lotus Domino. Show all posts

Lotus Notes DXL to remove Design Element Inherit from the design template

otusThere is no easy way in Domino Designer Client to clear the “Inherit from the design template” design element property from all design elements. The best you can do is to view all the forms, highlight those that show as inheriting from a design template as clear the property. But you have repeat this for Forms, Views, Agents, Script Libraries, etc.

When copying and pasting design elements from one database to another, if the source database is defined as a template then the following dialog box will appear:


If you answer yes to this prompt then the design element will be set to inherit from the source database.

To clear the property from all design elements use the following Agent code, which uses DXL to export, update and overwrite the design element.
Sub Initialize

Dim session As New NotesSession
Dim db As NotesDatabase
Dim note As NotesDocument
Dim noteCollection As NotesNoteCollection
Dim stream As NotesStream
Dim domParser As NotesDOMParser
Dim exporter As NotesDXLExporter
Dim importer As NotesDXLImporter
Dim attrib As NotesDOMAttributeNode
Dim nid As String
Dim found As Boolean
Dim i As Integer

Set db = session.CurrentDatabase

'Get a note collection of all the design elements
Set noteCollection = db.CreateNoteCollection(False)
noteCollection.SelectAllFormatElements False
noteCollection.SelectAllDesignElements True
noteCollection.BuildCollection

'Loop through the note collection
nid = noteCollection.GetFirstNoteId
For i = 1 To noteCollection.Count
Set note = db.GetDocumentByID(nid)

'Create a stream to store the DXL export output
Set stream = session.CreateStream
Set exporter = session.CreateDXLExporter
'Create a DOMParser to manage the DXL
Set domParser = session.CreateDOMParser(exporter, stream)
'Export the design element to the DOMParser
exporter.SetInput note
exporter.SetOutput domParser
exporter.Process

'Get the fromtemplate attribute from the exported XML
Set attrib = domParser.Document.DocumentElement.GetAttributeNode("fromtemplate")

'If the fromtemplate attribute exists and is not blank we need to blank it and import the DXL
If attrib.isNull = False Then
If attrib.AttributeValue <> "" Then
attrib.AttributeValue = ""
'Serialize the DXL so the importer has data to work with
domParser.Serialize
Set importer = session.CreateDXLimporter(stream, db)
importer.DesignImportOption = DXLIMPORTOPTION_REPLACE_ELSE_CREATE
importer.Import
End If
End If

nid = noteCollection.GetNextNoteId(nid)
Next

End Sub

Domino Keyword Lookups, jQuery & JSON

In Domino 8 it became possible to return a view in JSON format using &outputformat=JSON querystring parameter.

Here’s a simple view in Notes:

















Here is what the JSON looks like:

{
  “@timestamp”: “20090303T123231,91Z”,
  “@toplevelentries”: “3″,
  “viewentry”: [
    {
      "@position": "1",
      "@noteid": "8000000C",
      "@children": "4",
      "@descendants": "4",
      "@siblings": "3",
      "entrydata": [
        {
          "@columnnumber": "0",
          "@name": "Index",
          "@category": "true",
          "text": {
            "0": "Option A"
          }
        }
      ]
    },
    {
      “@position”: “1.1″,
      “@unid”: “84FE562575501BE88025755F0031E1B1″,
      “@noteid”: “8F6″,
      “@siblings”: “4″,
      “entrydata”: [
        {
          "@columnnumber": "1",
          "@name": "Choice",
          "textlist": {
            "text": [
              {
                "0": "Choice A1"
              }
            ]
          }
        }
      ]
    },
    {
      “@position”: “1.2″,
      “@unid”: “84FE562575501BE88025755F0031E1B1″,
      “@noteid”: “8F6″,
      “@siblings”: “4″,
      “entrydata”: [
        {
          "@columnnumber": "1",
          "@name": "Choice",
          "textlist": {
            "text": [
              {
                "0": "Choice A2"
              }
            ]
          }
        }
      ]
    },
    {
      “@position”: “1.3″,
      “@unid”: “84FE562575501BE88025755F0031E1B1″,
      “@noteid”: “8F6″,
      “@siblings”: “4″,
      “entrydata”: [
        {
          "@columnnumber": "1",
          "@name": "Choice",
          "textlist": {
            "text": [
              {
                "0": "Choice A3"
              }
            ]
          }
        }
      ]
    },
    {
      “@position”: “1.4″,
      “@unid”: “84FE562575501BE88025755F0031E1B1″,
      “@noteid”: “8F6″,
      “@siblings”: “4″,
      “entrydata”: [
        {
          "@columnnumber": "1",
          "@name": "Choice",
          "textlist": {
            "text": [
              {
                "0": "Choice A4"
              }
            ]
          }
        }
      ]
    },
    {
      “@position”: “2″,
      “@noteid”: “80000010″,
      “@children”: “4″,
      “@descendants”: “4″,
      “@siblings”: “3″,
      “entrydata”: [
        {
          "@columnnumber": "0",
          "@name": "Index",
          "@category": "true",
          "text": {
            "0": "Option B"
          }
        }
      ]
    },
    {
      “@position”: “2.1″,
      “@unid”: “866C6FA4AEA492158025755F00328A60″,
      “@noteid”: “8FA”,
      “@siblings”: “4″,
      “entrydata”: [
        {
          "@columnnumber": "1",
          "@name": "Choice",
          "textlist": {
            "text": [
              {
                "0": "Choice B1"
              }
            ]
          }
        }
      ]
    },
    {
      “@position”: “2.2″,
      “@unid”: “866C6FA4AEA492158025755F00328A60″,
      “@noteid”: “8FA”,
      “@siblings”: “4″,
      “entrydata”: [
        {
          "@columnnumber": "1",
          "@name": "Choice",
          "textlist": {
            "text": [
              {
                "0": "Choice B2"
              }
            ]
          }
        }
      ]
    },
    {
      “@position”: “2.3″,
      “@unid”: “866C6FA4AEA492158025755F00328A60″,
      “@noteid”: “8FA”,
      “@siblings”: “4″,
      “entrydata”: [
        {
          "@columnnumber": "1",
          "@name": "Choice",
          "textlist": {
            "text": [
              {
                "0": "Choice B3"
              }
            ]
          }
        }
      ]
    },
    {
      “@position”: “2.4″,
      “@unid”: “866C6FA4AEA492158025755F00328A60″,
      “@noteid”: “8FA”,
      “@siblings”: “4″,
      “entrydata”: [
        {
          "@columnnumber": "1",
          "@name": "Choice",
          "textlist": {
            "text": [
              {
                "0": "Choice B4"
              }
            ]
          }
        }
      ]
    },
    {
      “@position”: “3″,
      “@noteid”: “80000014″,
      “@children”: “1″,
      “@descendants”: “1″,
      “@siblings”: “3″,
      “entrydata”: [
        {
          "@columnnumber": "0",
          "@name": "Index",
          "@category": "true",
          "text": {
            "0": "Option C"
          }
        }
      ]
    },
    {
      “@position”: “3.1″,
      “@unid”: “B6C86E0C587E08CB802575620031CA0F”,
      “@noteid”: “8FE”,
      “@siblings”: “1″,
      “entrydata”: [
        {
          "@columnnumber": "1",
          "@name": "Choice",
          "text": {
            "0": "Choice C1"
          }
        }
      ]
    }
  ]
}



Using jQuery and its incumbent JSON AJAX methods we can return data from the view and process it.
Below is a simple form which has 2 select option drop downs on it:











When the User chooses an Option from the ‘Option’ drop down, a set of choices specific to the selected option need to be offered in the ‘Choice’ field.

Here is the code from the JSHeader
function Option_changed()
{    
    //URL to the view with the restricttocategory set to the selected choice
    var url = dbpath + ‘/keywords?readviewentries&outputformat=json&restricttocategory=’ + $(‘#Option option:selected’).text()
    //Select object
    select = $(‘#Choice’)                    
    //Default option
    options = ‘’
    //jQuery AJAX call to return JSON
    $.getJSON(url,function(data) {    
        //Check if we have any rows
        if(data.viewentry){
            //Loop through the rows
            $.each(data.viewentry, function(i, item){        
                $.each(item.entrydata, function(i, item){
                    //If the column contains multi-value
                    if(item.textlist){
                        //Loop through the multi-value column data                    
                        $.each(item.textlist, function(i, item){
                            //Loop through the text values
                            $.each(item, function(i, item){    
                                options += ‘’
                            })                        
                        })                        
                    } else {
                        //No multi-value so just grab the text
                        $.each(item.text, function(i, item){
                            options += ‘’
                        })
                    }
                })
            })
            //Loop through the columns
            select.html(options)
        }
    })
    //
    $(‘#Choice’).html(options)        
}

Domino: Read a file attachment without detaching

The function below shows how you can read a file attachment, in this case a text or csv file into a string without detaching it to disk.
Function getAttachmentData

 Dim doc As NotesDocument
 Dim stream As NotesStream
 Dim export As NotesDXLExporter
 Dim mime As NotesMimeEntity
 Dim txt As String
 Dim Start As Double
 Dim Finish As Double
 Dim fileData As String

 On Error Goto processError

 If Not dataDictView Is Nothing  Then Set doc = dataDictView.getDocumentByKey(|ARCHIVE CSV FILE| , True ) 

 If Not doc Is Nothing Then
  Set stream = session.CreateStream
  Set export = session.CreateDXLExporter
  'Convert the document to DXL
  export.setInput doc
  export.setOutput stream
  export.process
  'Process the export into a string file (as long as its less than 2GB)
  txt=stream.ReadText
  txt = Replace(txt, Chr(10), ||)
  'Find the  tags and read what's between them
  Start=Instr(1,txt,||)
  Finish=Instr(1,txt,||)
  fileData=Mid(txt,Start +10, Finish-Start-11)

  'Truncate the stream and write the filedata into it
  stream.Truncate
  stream.WriteText fileData

  'Setup a NotesMIMEEntity to decode the Base64 string
  Set mime = doc.CreateMIMEEntity(|MIMEEntity|)
  mime.SetContentFromText stream, |text/plain;charset=UTF-8|, ENC_BASE64
  mime.DecodeContent
  getAttachmentData = mime.ContentAsText
 End If

 Exit Function

processError:

 currentlog.LogError Err, |Error: | & Err & |: | & Error & | on line | & Erl & | in Agent: getAttachmentData|
 Exit Function

End Function