Remove Properties from a Design that stop Elements from being updated during a Design Replace

Function FreeDatabaseDesign(db As NotesDatabase, inheritfromtemplate As Boolean, prohibitreplacerefresh As Boolean, propagateprohibition As boolean) As Boolean
	Const CHAR_FLAG_1 = "P"
	Const CHAR_FLAG_2 = "r"
	Dim notecol As NotesNoteCollection
	Dim doc As NotesDocument
	Dim noteid As String
	Dim id As String
	Dim x As Integer
	Dim tempval As String
	Dim cansave As Boolean
	On Error GoTo ErrorHandler
	' Specify True to collect everything by default. This will be Designs and Documents
	Set notecol = db.CreateNoteCollection(true)
	' Remove Documents from Collection. We only want Design Elements
	notecol.SelectDocuments = False
	Call notecol.BuildCollection
	noteid = notecol.GetFirstNoteId
	' Loop through each Design Element
	For x = 1 To notecol.Count
		id = notecol.GetNextNoteId(noteid)
		Set doc = db.GetDocumentByID(noteid)
		If Not( doc Is Nothing ) Then
			cansave = False
			' There are 3 Properties that this code will check for:
			' - Inherit from Design Template - ($Class = Template Name)			
			' - Prohibit Design Refresh or Replace to modify - ($Flags = P)
			' - Propagate this prohibition of design change - ($Flags = r)
			If (prohibitreplacerefresh = True) Or (propagateprohibition = True) Then
				If doc.hasItem("$Flags") Then
					If (prohibitreplacerefresh = True) And (InStr(doc.~$Flags(0),CHAR_FLAG_1)) Then
						' Remove the Character P from Field
						tempval = Replace(doc.~$Flags(0), CHAR_FLAG_1, "")
						Call doc.Replaceitemvalue("$Flags", tempval)
						cansave = true

					End If 
					If (propagateprohibition = True) And (InStr(doc.~$Flags(0),CHAR_FLAG_2)) Then
						' Remove the Character P from Field
						tempval = Replace(doc.~$Flags(0), CHAR_FLAG_2, "")
						Call doc.Replaceitemvalue("$Flags", tempval)
						cansave = True

					End If 
				End If				
			End If

			If inheritfromtemplate = True Then
				If doc.hasItem("$Class") Then
					If doc.~$Class(0) <> "" Then
						Call doc.Replaceitemvalue("$Class", "")
						cansave = True
					End If
				End If
			End If

			' Check if we have to save Design Element
			If cansave Then
				Call doc.Save(true, false)
			End If

		End If      
		noteid = id
	' Return True that the Code ran Successfully
	FreeDatabaseDesign = true
	Exit Function
	' Print Error and Return False
	Print "FreeDatabaseDesign Function Error: " + Error$ + " - Line: " + CStr(Erl)
	FreeDatabaseDesign = false
	Resume Done

End Function

I've seen many environments where Production Databases have Design Elements that are prohibited from being updated, etc. This LotusScript function will allow you to provide it a NotesDatebase Object, with 3 parameters, and it will do the rest.

If you use it as a Function, it will return a True or False. False meaning the code did not execute completely.


Dim ss As New NotesSession
Dim db As NotesDatabase
Dim myresult As Boolean

Set db = ss.CurrentDatabase

If db.Isopen Then
myresult = FreeDatabaseDesign(db, true, true, true)

End If

Parameter 1 - NotesDatabase - The Notes Database that you want to process
Parameter 2 - Boolean - Do you want to check and remove the "Inherit from Design Template" Value.
Parameter 3 - Boolean - Do you want to check and remove the "Prohibit Design Refresh or Replace to modify" Property.
Parameter 4 - Boolean - Do you want to check and remove the "Propagate this prohibition of design change" Property.

John V Jardin
November 7, 2012 10:30 AM

All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.

No comments yetLogin first to comment...