Annoying Problem

Hi,

I have forms for my project and i have inserted a field called Status on each of those.

When a new user opens the form, the status is “Composing” however when they submit the form by pressing the button, i have got the status to change to “Form Submitted” and the admin staff is able to see this status change also when following the doc link on the email.

On the same form, the admin staff will need to open the second form to record more information so the status would still be “Form Submitted”. However, when the user has filled the form… they will have to save the changes by pressing on the save button which is just a simple file save command. Once the user has pressed the save button, the approve and reject button then appear (as these were currently hidden) and the admin user will then have the option of whether to approve or reject the request.

If the admin user clicks on the approve button, again an email will be sent out and the status will change to “approved”…if for some reason the admin user needs to reject the form after approving it i need to status to change to “rejected” but the status dont appear to work.

Im not very good at lotus script so i have used formula.

and this is what my code is so far…

@If(Status=“”; “Form Submitted”; Status); This is put on the status field

Approve Button***

Approved

@SetField(“Status”; “Approved”);

@Command([FileSave]); @MailSend(“user/IT/blah”; “user/IT/blah”; “”; “Request Form: Approval Confirmation”; “This an e-mail notification is for FYI purposes only.” + @NewLine + @NewLine + “Attached is a link with a copy of the new IT request and event logging form from the following person: " + @UserName;”";[IncludeDoclink]);

@Command([FileSave]);

@Command([FileCloseWindow])

reject***

@SetField(“Status”; “Reject”);

@Command([FileSave]); @MailSend(“user/IT/blah”; “user/IT/blah”; “”; “Request Form: Reject Confirmation”; “This an e-mail notification is for FYI purposes only.” + @NewLine + @NewLine + “Attached is a link with a copy of the new IT request and event logging form from the following person: " + @UserName;”";[IncludeDoclink]);

@Command([FileSave]);

@Command([FileCloseWindow])

Does anyone know what Im doing wrong??

Thanking you in advance

Subject: Annoying Problem

Join the fun… do it with LotusScript… here is how:Keep your save button. But when someone presses it, instead of saving the doc, you run an agent… like this:

@Command([ToolsRunMacro];“Save Form”)

Here is the agent:

When you create the agent… set it’s Target to ‘None’ and give it the same name you put in the button above… ‘Save Form’

This agent will allow you to use field validations on your form too.

Sub Initialize

On Error 4168 Resume Next ' allow for bad names

On Error 4294 Resume Next ' allow for bad names

On Error 4295 Resume Next ' allow for bad names

On Error 4000 Resume Next ' allow for bad names

On Error 4160 Resume Next ' allow for bad names



Dim s As New NotesSession

Dim w As New NotesUIWorkspace

Dim db As NotesDatabase

Dim uidoc As NotesUIDocument

Dim backendDoc As NotesDocument

Dim doc As NotesDocument

Dim userName As New NotesName(s.UserName)

Dim rtitem As NotesRichTextItem



Set db = s.currentdatabase

Set uidoc = w.currentdocument



On Error 4412 Goto cleanexit 'field validation error

Call uidoc.Save

Set backendDoc = uidoc.Document



Set doc = New NotesDocument( db )

doc.Form = "Memo"

Set rtitem = doc.CreateRichTextItem( "Body" )

Set rtitem = doc.getFirstItem("Body")

'now look at the status field and send the appropriate message

Select Case backenddoc.GetItemValue("Status")(0)

Case "Approved"

	doc.Sendto = "user/IT/blah"

	doc.CopyTo = "user/IT/blah"

	doc.Subject = "Request Form Approval Confirmation"

	Call rtitem.AppendText( "This an e-mail notification is for FYI purposes only." )

Case "Reject"

	doc.Sendto = "user/IT/blah"

	doc.CopyTo = "user/IT/blah"

	doc.Subject = "Request Form: Reject Confirmation" 

End Select

Call rtitem.AddNewLine( 2 , True )

Call rtitem.AppendText( "Attached is a link " )

Call rtItem.AppendDocLink( backenddoc, db.Title )

Call rtitem.AppendText( " with a copy of the new IT request and event logging form from the following person: " )

Call rtitem.AppendText( userName.Abbreviated & "." )

Call doc.Send(False)

theEnd:

On Error Resume Next

Call uidoc.FieldSetText( "SaveOptions", "0" )

Call uidoc.Close(True)

cleanexit:

Exit Sub

End Sub

Subject: Annoying Problem

I forgot to add one more thing:Put a hidden, editable field called SaveOptions onto your form.

Any questions, problems… post here and I’ll be back to help.

:slight_smile:

Subject: RE: Annoying Problem

Hi Stan,

Thank you for your response.

I have implemented the code you have given me into an agent, and also inserted an editable field called “Save Options”. However, When i run the form, add some data, the form appears to save, but I dont seem to recieve an email?

Any ideas as to why this is happening?

Thank you for taking the time to help me - i greatly apreciate it.

Subject: RE: Annoying Problem

The first few lines suppress an error.Add an apostrophe at the beginning of each of these lines so they turn ‘green’… this will disable them.

Turn on LotusScript debug with File Tools, Debug LotusScript

Then create a new doc and press your save button.

LotusScript debugger will then open.

You will see a few new buttons across the top of your debug window…

  1. Continue = executes the lotusscript code ‘full speed’ and if there is an error, it stops on that line so you can see where the error happened… great for debugging.

  2. Step Into = this will walk through the code one line at a time! This is great for you to see what is happening… as it progresses… at the bottom of your screen, notice the tab titled ‘Variables’ - great info here… press the Step Into button again and continue to what what happens in the Variables tab. You can actually see all the elements within the database… views, view columns, documents, all the document’s field values - everything. This is a great way to learn all the neat things you can read/change as you progress through lotusscript options (things you might not think of, are possible). Keep pressing Step Into and eventually you will get to your error.

By the way… the code snippet I pasted had bogus email addresses… you changed that didn’t you? Also, as a suggestion, use the internet email addresses within these fields instead of the notes names to avoid possibillity that someone’s name is also in the users personal addressbook.

Please let me know your progress… and also how you do with the debugger!

:smiley:

Subject: RE: Annoying Problem

Hi Stan.

Yeah I changed the email address accordingly and have run through the debugger.

I seemed to get an error along the lines of “no recipients to send to” or something yet…i had defined the correct addresses…

Hope that makes sense

Thanks

Subject: RE: Annoying Problem

Do you have a line that says this?doc.SendTo = “valid@emailaddress.com

This is who it is mailed to.

Optionally, you could copy it to another address with:

doc.CopyTo = “anothervalid@emailaddress.com

If that doesn’t fix it, please paste your code so I can see what you have.

:slight_smile:

Subject: RE: Annoying Problem

Hi,

Ive just looked through the code and i do have the doc.sendto.

Here is the code…

Sub Initialize

'On Error 4168 Resume Next ' allow for bad names

'On Error 4294 Resume Next ' allow for bad names

'On Error 4295 Resume Next ' allow for bad names

'On Error 4000 Resume Next ' allow for bad names

'On Error 4160 Resume Next ' allow for bad names



Dim s As New NotesSession

Dim w As New NotesUIWorkspace

Dim db As NotesDatabase

Dim uidoc As NotesUIDocument

Dim backendDoc As NotesDocument

Dim doc As NotesDocument

Dim userName As New NotesName(s.UserName)

Dim rtitem As NotesRichTextItem



Set db = s.currentdatabase

Set uidoc = w.currentdocument



On Error 4412 Goto cleanexit 'field validation error

Call uidoc.Save

Set backendDoc = uidoc.Document



Set doc = New NotesDocument( db )

doc.Form = "Memo"

Set rtitem = doc.CreateRichTextItem( "Body" )

Set rtitem = doc.getFirstItem("Body")

'now look at the status field and send the appropriate message

Select Case backenddoc.GetItemValue("Status")(0)

Case "Approved"

	doc.Sendto = "Mark Sugar/IT/comapny"

	doc.CopyTo = "Tammy Davis/IT/company"

	doc.Subject = "Request Form Approval Confirmation"

	Call rtitem.AppendText( "This an e-mail notification is for FYI purposes only." )

Case "Reject"

	doc.Sendto = "Tammy Davis/IT/company"

	doc.CopyTo = "Mark Sugar/IT/comapny"

	doc.Subject = "Request Form: Reject Confirmation"

End Select

Call rtitem.AddNewLine( 2 , True )

Call rtitem.AppendText( "Attached is a link " )

Call rtItem.AppendDocLink( backenddoc, db.Title )

Call rtitem.AppendText( " with a copy of the new IT request and event logging form from the following person: " )

Call rtitem.AppendText( userName.Abbreviated & "." )

Call doc.Send(False)

theEnd:

On Error Resume Next

Call uidoc.FieldSetText( "SaveOptions", "0" )

Call uidoc.Close(True)

cleanexit:

Exit Sub

End Sub

Thanks for your help

Subject: RE: Annoying Problem

I occurs to me that since you are getting a message that there is no one to send it to, I believe the issue is the Status field is either blank, or not one of the two values you are expecting it to be: “Approved” or “Reject”

For debugging purposes:

Please confirm by adding these lines just before your ‘Select Case’

msgbox(backenddoc.GetItemvalue(“Status”)(0))

Exit Sub

When you run your agent, it will now do a popup that shows the value of that field.

Within your code, you’re using Select Case… that means if Status is “Approved”… do this thing, if Status is “Reject” then do this thing… but if it’s neither, you are not setting the sendto.

You need to be sure you are handling every possibility. I suggest you either put a field validation formula on the Status field (make sure it is not blank) or set the Status field in this agent with:

Call backenddoc.ReplaceItemValue(“Status”, “Approved”)

Call backenddoc.save(True, False)

or modify your Select Case for what to do when ‘none of the above’ are found. This can be done with Case Else

Select Case backenddoc.GetItemValue(“Status”)(0)

Case “Approved”

doc.Sendto = “Mark Sugar/IT/comapny”

doc.CopyTo = “Tammy Davis/IT/company”

doc.Subject = “Request Form Approval Confirmation”

Call rtitem.AppendText( “This an e-mail notification is for FYI purposes only.” )

Case “Reject”

doc.Sendto = “Tammy Davis/IT/company”

doc.CopyTo = “Mark Sugar/IT/comapny”

doc.Subject = “Request Form: Reject Confirmation”

Case Else

doc.Sendto = “Tammy Davis/IT/company”

doc.Subject = “The dummy didn’t pick a Status!”

End Select

:slight_smile:

Don’t forget to remove the debugging lines after you confirm my suspicion.

Please let me know your progress. Today was a typical Monday, sorry for the delayed reply.