Link to home
Start Free TrialLog in
Avatar of deivakumar
deivakumar

asked on

Sending mail from a form designed on Lotus hosted in Web

Hi

Could you Please help me urgently.

I am basically an Lotus Domino Administrator and had been asked to develop small application on Lotus which is Requestor will submit his request through web and the same application will be accessed by approvers through lotus client and approve their requests.

In this scenario, there is a submit request button. Once the requestor fills the relevant details and clicks the submit button on web, immediately a mail should be sent to the approver about the new request for his action.
The approver is available in a field. All are internal users on the same server, but the requestors will access this form over web.

I had used a agent with send a mail in webquerysave. But its not working. When I used @mailsend in webquerysave, it sends mail when the requestor submits his request. But it goes with the server name and also I need a popup on the browser, once the requestor clicks the submit request button. I was trying to get the solution for the last 14 hours.
Nothing is working for me. Could anyone help me urgently on this?

I need bring it to online by tomorrow nite(deadly timeline)

Thanking You
Avatar of Sjef Bosman
Sjef Bosman
Flag of France image

Seems right to me. What's the code you use in the WebQuerySave agent?

Ehm, we don't like threats about deadlines and so... ;) but we'll try to help!
Avatar of deivakumar
deivakumar

ASKER

Sorry my friend! if the deadline hurts........................ Looking for your help thanks

------------------------------------------------------------------

Please find the agent (SendMail) which is in agent with the following settings.

Shared
Trigger - on event
Runtime - Action Menu Selection
Target - All new and modified Documents
------------------------------
The following code is available in agent - intialize

Dim session As New NotesSession
      Set db = session.CurrentDatabase
      Set maildoc = db.CreateDocument
      Dim doc As notesDocument
      Dim rtitem As NotesRichTextItem
      Dim Body As NotesRichTextItem
      
      Set doc = session.DocumentContext
      tmpreqname=doc.Txt_Author
      tmpcontact=doc.ID
      
      maildoc.Form = "memo"
      maildoc.SendTo = doc.Analyst
      maildoc.Subject = "You have a new request from "+tmpreqcomp
      Set Body=New NotesRichTextItem(maildoc,"Body")
      Set rtitem = New NotesRichTextItem( maildoc, "Body" )
      message="Please review new request from "+ tmpreqname+" from "+tmpreqcomp+"."
      Call rtitem.AppendText(message)
      Call Body.AddNewLine(2)
      message1="Click here to open the form=========>>"
      Call Body.AppendText(message1)
      Call Body.AppendDocLink(doc,"Please Click this Link to open the Document")
      Call maildoc.send(False)

In this code, Txt_Author is a computed field having formula ( @Name([CN];@UserName) ) and ID is an another computed field ( which is generating a request id based on time and date) and  Analyst is the field, where the approvers mail Id are stored will be selected by another field based on their respective region.

I dont' want to send any text or anything on body of the mail. Just to send a mail in the subject saying that a request with ID no from the field - ID is waiting for your approval.

-----------------------------------

The following formula had been available at webquerysave

@Command([RunAgent];MailSend)
Probably the agent never ran. The target is wrong, it has to be None.

From the Designer Help db:
Using the Agent Properties box, do the following:
- Check the "Shared" option when you create the agent.
- Set the agent trigger to "On event" and either "Agent list selection" or "Action menu selection."
- Set the agent target to "None" for agents that work on the current document such as those launched from WebQueryOpen or WebQueryClose, or a form action or hotspot that works on fields in the current document.

Otherwise, I think you would have seen errors in the log.nsf database. Also, creating two richtext items with the name Body is impossible.

Dim session As New NotesSession
     Set db = session.CurrentDatabase
     Set maildoc = db.CreateDocument
     Dim doc As notesDocument
     Dim rtitem As NotesRichTextItem
     Dim Body As NotesRichTextItem
     
     Set doc = session.DocumentContext
     tmpreqname=doc.Txt_Author(0) ' <---
     tmpcontact=doc.ID(0) ' <---
     
     maildoc.Form = "memo"
     maildoc.SendTo = doc.Analyst(0) ' <---
     maildoc.Subject = "You have a new request from "+tmpreqcomp
     Set Body=New NotesRichTextItem(maildoc,"Body")
'     Set rtitem = New NotesRichTextItem( maildoc, "Body" ) ' <---
     message="Please review new request from "+ tmpreqname+" from "+tmpreqcomp+"."
     Call Body.AppendText(message) ' <---
     Call Body.AddNewLine(2)
     message1="Click here to open the form=========>>"
     Call Body.AppendText(message1)
     Call Body.AppendDocLink(doc,"Please Click this Link to open the Document")
     Call maildoc.send(False)
I had done the following changes. Could you please review and advise?

Shared
Trigger on event
Runtime - Action Menu Selection
Target - None.

----------------------------------------------------------------------
Dim session As New NotesSession
      Set db = session.CurrentDatabase
      Set maildoc = db.CreateDocument
      Dim doc As notesDocument
      Dim rtitem As NotesRichTextItem
      Dim Body As NotesRichTextItem
      
      Set doc = session.DocumentContext
      tmpreqname=doc.Txt_Author
      tmpcontact=doc.ID
      
      maildoc.Form = "memo"
      maildoc.SendTo = doc.Analyst
      maildoc.Subject = "You have a new request from "+tmpreqname
      Set Body=New NotesRichTextItem(maildoc,"Body")
      message="Please review new request from "+ tmpreqname+" from "+tmpcontact+"."
      Call maildoc.send(True)

------------------------------------------------------------------------------------
If I run this agent from designer then it gives an error saying that " object variable not set "

At end, there is no mail has been sent to the requestor
You can't run the agent from the Designer, because there is no current document, hence doc is Nothing, so the code will stop at the first line where the object doc is used. You have to run it as a web agent.

Secondly, the message isn't put into the mail. The following is allowed:
    Call Body.AppendText("Please review new request from "+ tmpreqname+" from "+tmpcontact+".")

Thirdly, you didn't copy all the code I changed above. It is maybe strange, but a reference to a field in a document yields an array. In the Notes object system, ALL NotesItems are potentially multi-value. So, if there is only one value, you still have to get the first value of the array. E.g. with Txt_Author:
    tmprequname= doc.Txt_Author
will stop execution right there, because you try to assign an array to a String variable... ah, now I see, tmpreqname isn't declared, therefore a Variant by default, and the statement is permitted. It will set the value of tmpreqname to an array. What you need is the first value of the aray:
    tmprequname= doc.Txt_Author(0)

And make it a good habit to declare ALL variables before you use them. To assist you, set Option Declare in the option section of the module. In the Programmer's Pane Properties, 2nd tab, you can set "Automatically add 'Option Declare' ".

If you want to follow the execution of a web agent, you can add some MsgBox calls. The output is sent to log.nsf and not to a screen. Like this:

     Dim session As New NotesSession
     Set db = session.CurrentDatabase
     Set maildoc = db.CreateDocument
     Dim doc As notesDocument
     Dim Body As NotesRichTextItem
     Dim tmpreqname As String
     Dim tmpcontact As String
     
     Set doc = session.DocumentContext
     tmpreqname=doc.Txt_Author(0)
     tmpcontact=doc.ID(0)
     
     maildoc.Form = "Memo"
     maildoc.SendTo = doc.Analyst(0)
     maildoc.Subject = "You have a new request from "+tmpreqname
     Set Body=New NotesRichTextItem(maildoc,"Body")
     Call Body.AppendText(Please review new request from "+ tmpreqname+" from "+tmpcontact+".")
     Call Body.AddNewLine(2)
     Call Body.AppendText("Click here to open the form=========>>")
     Call Body.AppendDocLink(doc,"Please Click this Link to open the Document")
     Call maildoc.send(False)
hi it looks like working but the doc.Analyst should be selected based on the other field.
ex. If the field Region is populated with " Tunis " by user, then the mail should be sent to approver " User1"
If the field Region is populated with "Congo" by user, then the mail should be sent to approver "User2"

Now all the approvers listed in a field "Analyst" which was manually selected by the requestors. I want to hide the approvers name from the requestors. The requestors should select only regions and mails should be sent to respective approvers.

Sorry for bothering you much........... Since Im just few steps away from hosting this apps, request your help on this.

thanks
Several ways to do that, this is the simplest.

field Region, Dialog list, editable, with all regions.

field Analyst, computed, formula:
    regions:= "Tunis":"Congo":"Anywhere":....;
    approvers:= "User1/ACME":"User2/ACME":"User1/ACME":...;
    @Replace(Region; regions; approvers)

These two lists have to be of the same length.

The next step could be that you remove names and regions from the source code of the form, and you develop a simple form with Analyst and Region, and a view, so you can do a @DbLookup.
thanks, its working for region with one approver.

here i hv another problem. for few regions, there are two approvers, both must be notifed on the same request.

how we can achieve this? appreciate ur kind help.thanks
That's your 3rd question... ;)

field Analyst, computed, formula:
    regions:= "Tunis":"Congo":"Anywhere":....;
    approvers:= "User1/ACME":"User2/ACME;User4/ACME":"User1/ACME":...;
    @Explode(@Replace(Region; regions; approvers); ";")

In one entry in the approvers list, put two names, separated by a ";"
Thanks friend! Can I add one more request.

How can you have unique request IDs for all the requestors? Pls. help. Thanks
ASKER CERTIFIED SOLUTION
Avatar of Sjef Bosman
Sjef Bosman
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
OK. Will do the same.Thanks for your continuous support.
Ah, you gave a B. Which means you're not fully satisfied? I even answered THREE questions! Could you please reconsider? Do read
    "How to grade" https://www.experts-exchange.com/help.jsp#hi73
No probs! my dear friend! can be esclated to A!
Smashing! If you would be so kind to post a (free) question in the Community Support TA?