User Input Required in Lotusscript

I am an administrator, not a developer, and I need some help adding a user prompt to some script. The script would either continue to run if the user choses “ok”, or it would stop if the user choses “cancel”. I’ve been able to do this with a message box in a different script, but cannot get it to work here. I have used the Help in designer and have been unsuccessful.Any assistance would be greatly appreciated. Here is the lotusscript:

Sub Click(Source As Button)

Const SPAMREPORTADDRESS = "test@cox.net" 'the email address used to report spam, uncomment to go live



Dim sess As New NotesSession

Dim ws As New NotesUIWorkspace



Dim db As NotesDatabase

Dim memo As NotesDocument, doc As NotesDocument

Dim col As NotesDocumentCollection

Dim mime As NotesMIMEEntity

Dim rtitem As NotesItem

Dim temp As Variant 'to get info from non-ASCII data

Dim i As Integer 'to count messages



Dim uiview As NotesUIView 'to update the inbox after messages have been moved

Dim mail As NotesRichTextItem 'the sent message

Dim item As NotesItem 'to process fields with multiple items (i.e. recieved)



sess.ConvertMime = False 'init mime conversion

Set db = sess.CurrentDatabase

Set col = db.UnprocessedDocuments

Set doc = col.GetFirstDocument()

If doc Is Nothing Then Exit Sub 'sanity check to abort early



Print "Reporting " + Cstr( col.Count ) + " selected documents as Spam to " + SPAMREPORTADDRESS + ". Please wait..."

i = 1



While Not(doc Is Nothing) 

	Set memo = db.CreateDocument

	Set mail = New NotesRichTextItem( memo, "Body" )

	

	Set mime = doc.GetMIMEEntity

	If Not(mime Is Nothing) Then

		Forall header In mime.HeaderObjects

			Call mail.AppendText( walkmime ( mime ) ) 'calls required function walkmime

		End Forall

		Call doc.CloseMIMEEntities 'allow clean switch to using items

		

		If Instr( doc.Subject(0), "SPAM Submission" ) = 0 Then 

			Call doc.ReplaceItemValue("Subject", "SPAM Submission > " + doc.Subject(0) ) 'remove [spam]

		End If

		

		memo.subject = doc.subject(0)

		Call memo.Send( False, SPAMREPORTADDRESS) 'forward spam report message

		

		Print "Successfully reported message " Cstr(i) + " of " + Cstr( col.Count ) +" ("+ doc.Subject(0) + ")" 

	Else

		Print "No MIME content found in message, not sending spam report. (the internet message may have been converted to Notes Format)"

	End If

	

	

	Call doc.Remove(True)

	Call ws.ViewRefresh

	

	Call sess.UpdateProcessedDoc( doc )

	i = i +1 'increment counter

Wend



Set uiview = ws.CurrentView

Call uiview.DeselectAll 'to prevent UI bugs

sess.ConvertMime = True 'revert mime conversion 

Beep

Print "Done reporting " + Cstr( col.Count ) + " document(s) as Spam."

End Sub


Function walkmime (mime As notesmimeentity) As String

'returns string of complete mime message

Dim mime2 As notesmimeentity 'for walking mime tree

walkmime = "" 'init string



While Not (mime Is Nothing)

	walkmime = walkmime & Chr(10) _

	& mime.Headers & Chr(10) _

	& mime.ContentAsText 

	

	Set mime2 = mime.GetFirstChildEntity 'get first child:

	

	If mime2 Is Nothing Then 'none? then get next sibling

		Set mime2 = mime.GetNextSibling

	End If

	

	If mime2 Is Nothing Then 'none? then get aunt/uncle :

		Set mime2 = mime.GetParentEntity

		If Not (mime2 Is Nothing) Then

			Set mime2 = mime2.GetNextSibling

		End If

	End If

	

	Set mime = mime2

Wend

End Function

Subject: User Input Required in Lotusscript

Hoping that you are running thi script from a view action button, my suggestion is to add a prompt if you have 1 or more documents in collection whether to proceed or not as follows:

Dim res As Integer (Add this with your existing dims)

…

…

…

Set col = db.UnprocessedDocuments

If not col is nothing then

Set doc = col.GetFirstDocument()

If not doc is nothing then

   res = ws.Prompt (PROMPT_YESNO, "Alert", "Do you want to proceed?")

   If res =1 then  'Executes if user select "Yes" to proceed

      .....

      .....

      All your remaining code

      .....

      .....

   Else

      Exit sub    ' Exists subroutine. Stops execution of code.

   End if

End if

End if

Subject: RE: User Input Required in Lotusscript

Hello, thank you very much for your response.

I receive an error “Object variable not set” after adding your suggestion. Yes, this is an action button in the Inbox.

I added your Dim, right below the rest of the existing Dims.

I added this piece directly below the Dims:

Set col = db.UnprocessedDocuments

If Not col Is Nothing Then

	Set doc = col.GetFirstDocument()

	If Not doc Is Nothing Then

		res = ws.Prompt (PROMPT_YESNO, "Alert", "Do you want to proceed?")

		If res =1 Then 'Executes if user select "Yes" to proceed

Then at the bottom, right above End Sub, I placed the last of your recommendation:

Else

			Exit Sub ' Exists subroutine. Stops execution of code.

		End If

	End If

End If 

More easily viewed, the entire code looks like this now:

Sub Click(Source As Button)

Const SPAMREPORTADDRESS = "test@cox.net" 'the email address used to report spam, uncomment to go live



Dim sess As New NotesSession

Dim ws As New NotesUIWorkspace



Dim db As NotesDatabase

Dim memo As NotesDocument, doc As NotesDocument

Dim col As NotesDocumentCollection

Dim mime As NotesMIMEEntity

Dim rtitem As NotesItem

Dim temp As Variant 'to get info from non-ASCII data

Dim i As Integer 'to count messages



Dim uiview As NotesUIView 'to update the inbox after messages have been moved

Dim mail As NotesRichTextItem 'the sent message

Dim item As NotesItem 'to process fields with multiple items (i.e. recieved)

Dim res As Integer 



Set col = db.UnprocessedDocuments

If Not col Is Nothing Then

	Set doc = col.GetFirstDocument()

	If Not doc Is Nothing Then

		res = ws.Prompt (PROMPT_YESNO, "Alert", "Do you want to proceed?")

		If res =1 Then 'Executes if user select "Yes" to proceed

			

			sess.ConvertMime = False 'init mime conversion

			Set db = sess.CurrentDatabase

			Set col = db.UnprocessedDocuments

			Set doc = col.GetFirstDocument()

			If doc Is Nothing Then Exit Sub 'sanity check to abort early

			

			Print "Reporting " + Cstr( col.Count ) + " selected documents as Spam to " + SPAMREPORTADDRESS + ". Please wait..."

			i = 1

			

			While Not(doc Is Nothing) 

				Set memo = db.CreateDocument

				Set mail = New NotesRichTextItem( memo, "Body" )

				

				Set mime = doc.GetMIMEEntity

				If Not(mime Is Nothing) Then

					Forall header In mime.HeaderObjects

						Call mail.AppendText( walkmime ( mime ) ) 'calls required function walkmime

					End Forall

					Call doc.CloseMIMEEntities 'allow clean switch to using items

					

					If Instr( doc.Subject(0), "SPAM Submission" ) = 0 Then 

						Call doc.ReplaceItemValue("Subject", "SPAM Submission > " + doc.Subject(0) ) 'remove [spam]

					End If

					

					memo.subject = doc.subject(0)

					Call memo.Send( False, SPAMREPORTADDRESS) 'forward spam report message

					

					Print "Successfully reported message " Cstr(i) + " of " + Cstr( col.Count ) +" ("+ doc.Subject(0) + ")" 

				Else

					Print "No MIME content found in message, not sending spam report. (the internet message may have been converted to Notes Format)"

				End If

				

				

				Call doc.Remove(True)

				Call ws.ViewRefresh

				

				Call sess.UpdateProcessedDoc( doc )

				i = i +1 'increment counter

			Wend

			

			Set uiview = ws.CurrentView

			Call uiview.DeselectAll 'to prevent UI bugs

			sess.ConvertMime = True 'revert mime conversion 

			Beep

			Print "Done reporting " + Cstr( col.Count ) + " document(s) as Spam."

		Else

			Exit Sub ' Exists subroutine. Stops execution of code.

		End If

	End If

End If 

End Sub

Did I put something in the wrong place?

Thanks again!

Subject: RE: User Input Required in Lotusscript

Hi,

I’ve tested this button using the original code found here, and it worked as expected.

You can try to copy the code and fill after the instructions and it will work.

As far as I understand you didn’t copied the function called walkmime, and this is really important.

Just copy the whole code and paste it inside a new agent using “initialize”, and not “Click” as you are using.

HTH,

Daniel

Subject: RE: User Input Required in Lotusscript

Please disregard the previous post. I played around with moving the new, additional code into a different place in the existing code and it seems to be working wonderfully now.Thank you so very much for your help.