This fragment of code shall help you to remove the mark against "Prohibit design refresh or replace to modify" in the design document properties of the design elements in the database against which the agent is run
'**********************************************************************************'@Author : Karthikeyan A
'@Purpose : To remove the mark against "Prohibit design refresh or replace to modify" in the design document
' properties of the design elements in the database against which the agent is run
'@Note : Can be used as a agent
'@Type : Sub
'@Name : agProhibitFlagRemover
'@Param : Nothing
'@Return : Nothing
'**********************************************************************************Sub ProhibitFlagRemover
'initiation
'handle errors in case of abrupt termination
On Error Goto errHandler
'declare all necessary variables and objects required for further manipulation
Dim session As New NotesSession
Dim workspace As New NotesUIWorkspace
Dim Server_Name As NotesName
Dim noteCol As NotesNoteCollection
Dim targetDB As NotesDatabase
Dim designDoc As notesdocument
Dim mailDoc As NotesDocument
Dim dbfile As Variant
Dim mailFile As Variant
Dim sendTo As String
Dim noteID As String
Dim flagValue As String
Dim updatedList As String
Dim serverName As String
Dim count As Integer
Dim accessLevel As Integer
Dim confirmation As Integer
Dim itr As Integer
'open the open database dialog box
dbFile= workspace.Prompt(13,"Choose database","Please select a database to process")
'if the user presses escape or the cancel button then skip the process
If Isempty(dbFile) Then
Exit Sub
End If
'set the handle for the target database from the users' selection
Set targetDB=session.GetDatabase(dbFile(0),dbFile(1),False)
'if the handle for the target database is not set then prompt the user and exit
If Not targetDB.IsOpen Then
Msgbox "The database that you have selected is not a valid file",,"Invalid file "
Exit Sub
End If
'check the current user's access level for the selected database
accessLevel=targetDB.QueryAccess(session.UserName)
'if the user does not have designer or higher access then inform the user and exit
If accessLevel < ACLLEVEL_DESIGNER Then Msgbox "You do not have sufficient access to perform this operation in the chosen database",,"Access denied" Exit Sub End If 'inform the user that proceeding further will sign all the design documents in the database and ask for confirmation 'if he/she wants to proceed else ask him to abort if he wants to use a different id confirmation= workspace.Prompt(PROMPT_YESNO,"Alert","Proceeding further will sign all the design elements in the database by your ID.If you are sure please click ""Yes"" to proceed." _ & Chr(13) & "Or if you want to switch to a different id before proceeding please click ""No""") 'if the user does not confirm then exit process else proceed If confirmation=0 Then Exit Sub End If 'get the collection of all design documents in the database Set noteCol=targetDB.CreateNoteCollection(True) 'build the note collection of the design documents Call noteCol.BuildCollection 'loop through the design documents and remove the "Prohibit Design Refresh" flag if enabled and update the status bar 'get the note id of the first design document in the database noteID=noteCol.GetFirstNoteId 'initializing the list of design documents that are updated as null updatedList="" itr=1 For count=1 To noteCol.Count 'set the handle handle for the design document using the note id found from the collection Set designDoc=targetDB.GetDocumentByID(noteID) 'look into the $Flag item in the design document to see if "Prohibit design refresh or replace to modify" is marked or not flagValue=designDoc.GetItemValue("$Flags")(0) 'if yes then remove it and save the design document If Instr(flagValue,"P") Then 'remove the prohibition mark flagValue=Replace(flagValue,"P","") 'update the design document Call designDoc.ReplaceItemValue("$Flags",flagValue) 'save the design document Call designDoc.Save(True,False) 'update the updated list of documents updatedList=updatedList & Cstr(itr) & ". " & designDoc.GetItemValue("$Title")(0) & Chr(13) itr=itr+1 'update the status bar Print designDoc.GetItemValue("$Title")(0) & " has been updated by removing the ""Prohibit design refresh or replace to modify"" flag" End If 'get the noteID of the next design document in the note collection noteID=noteCol.GetNextNoteId(noteID) Next 'if there are no design documents updated then skip the process else proceed If updatedList<>"" Then
'if the chosen database is in local then mark the servername as local else use the server name in which the database exists
If dbFile(0)="" Then
serverName="Local"
Else
serverName=dbFile(0)
End If
'detail the message that is to be mailed to the user
updatedList= "The database """ & dbFile(1) & """ in server """ & serverName & """ with title """ & dbFile(2) & """" _
& Chr(13) & Chr(13) & " has been processed and the ""Prohibit design refresh or replace to modify"" property has been unchecked " _
& Chr(13) & Chr(13) & updatedList
'get the name of the server in which the current database resides
Set Server_Name=session.CreateName(session.CurrentDatabase.Server)
'get the mail file name of the current user
mailFile=Evaluate({@NameLookup([NoUpdate];@Name([CN];"}+session.CommonUserName+{");"MailFile")})
'see if the current user has a mail file associated with his ID. if yes then send the mail to him else
' allow him to chose a mail address to send the mail to
If mailFile(0)<>"" Then
sendTo=session.UserName
Else
sendTo=workspace.PickListStrings(PICKLIST_NAMES,False)
'if the user does not pick any name to send mail to, then inform the user about the status and exit
If sendTo="" Then
Msgbox "The process has been completed successfully and you can find the list of design elements that were updated in the status bar" ,,"Successfully updated the database"
Exit Sub
End If
End If
'prepare a mail document and send the mail to the current user
Set MailDoc=session.CurrentDatabase.CreateDocument
mailDoc.Form="Memo"
mailDoc.sendTo=sendTo
mailDoc.Subject=dbFile(1) & " database in " & serverName & " has been updated"
mailDoc.Body=updatedList
Call mailDoc.Send(False)
'prompt the user that the information has been mailed to him and exit
Msgbox "The process has been completed successfully and the list of changes have been mailed to "& sendTo ,,"Successfully updated the database"
Exit Sub
End If
'prompt the user that no design document has been updated and exit
Msgbox "The process has been completed successfully and no change was made to the database",,"No changes were required"
Exit Sub
'prompt the errors that resulted in abrupt termination
errHandler:
Msgbox "Error: ***" & Error & "*** encountered on line *** " & Cstr(Erl) & " *** with error number *** " & Cstr(Erl) & " ***"
Exit Sub
End Sub
No comments:
Post a Comment