Link to home
Start Free TrialLog in
Avatar of KTTKTT
KTTKTTFlag for United States of America

asked on

How do you make a hyperlink within an email Notes button for a url - I'm using formula for the email text - urgent

How do you make a hotspot text hyperlink within an email Notes button for a url - I'm using formula for the email text.  When the button is clicked the email newsletter is composed as a mail message , but need to make some of the text in the email note hyperlink.  Thanks


this doesnt work:   A HREF=\"http://www.ibm.com\">"BM's Home Site"
Avatar of Bill-Hanson
Bill-Hanson
Flag of United States of America image

>> "I'm using formula for the email text"

You can't add formatted text, hyperlinks, etc using @Formula.  You'll have to switch to LotusScript to provide this functionality.

As a workaround, you could just put the URL directly in the body.  Most email clients will automatically turn URLs into hyperlinks.
Avatar of KTTKTT

ASKER

Would this be the way to render the text as hyperlink in lotusScript?  Searching help, but not finding exactly what I need.

Call richText.AppendStyle(richStyle)
  Call richText.AppendText(A HREF=\"http://www.ibm.com">Click here</a></p>)
Nope.

If you want to generate an HTML memo, you'll need to use the MIME classes.

First, tell the Notes Session not to automatically convert MIME while we are working on it.  We'll set this back to True later...

      Dim sess As New NotesSession
      sess.ConvertMime = False

Next, create the MIME entity.  This MIME will be displayed in the "Body" of the memo (Notes uses RichText fields to display MIME).

      Dim body As NotesMimeEntity
      Set body = doc.CreateMIMEEntity("Body")

Next, use a stream to set the MIME's HTML part to your HTML string...

      Dim stream As NotesStream
      Dim html as String
      html = {A HREF="http://www.ibm.com">Click here</a>}
      Set stream = sess.CreateStream
      Call stream.WriteText(html)
      Call mimeBody.SetContentFromText(stream, {text/html; charset="iso-8859-1"}, ENC_QUOTED_PRINTABLE)

All that's left is to restore the session property and close our MIME entity.

      sess.ConvertMime = True
      Call doc.CloseMIMEEntities(True, "Body")

That's it.
Avatar of KTTKTT

ASKER


thanks

Getting error "Not a sub of function name" on this line:
Call mimeBody.SetContentFromText(stream, {text/html; charset="iso-8859-1"}, ENC_QUOTED_PRINTABLE)
My bad.

I defined the MIME Entity with the variable 'body', but used 'mimeBody' later on.  Just change 'mimeBody' to 'body'.

This brings up an important point.  I recommend this to everyone, and require it of my own developers...  Always include 'Option Declare' in your Options module.  This helps prevent many errors.  If you had this option enabled, the compiler would have told you right away that mimeBody was not defined.
So, how's this working out for you?
Avatar of KTTKTT

ASKER

I'm trying to implement the code above with a LotusScript mail forward so when user clicks email button, a memo is composed with the To, Subject , body already filled in, and the user just forwards that mail to others.  I've done this before with simple actions and formula, so struggling a bit to pull it together in lotusScript.  The button will have a hyperlink as you've coded above in the body of the note for a url.  
I understand.  Making the jump to a new language can be confusing.

So, here are a couple of presents for you...

First, a simple function that will compose an HTML memo and display it to the user for sending.  The only problem with this function is that it does not pull in the user's signature.  If that is not a problem, then this is the function that you should use.
Public Function ComposeMimeMemo(Byval subject As String, Byval html As String) As NotesUIDocument
	
	Dim sess As New NotesSession
	Dim db As New NotesDatabase("", "")
	Dim doc As NotesDocument
	Dim body As NotesMimeEntity
	Dim stream As NotesStream
	
	' create the MIME memo
	Call db.OpenMail
	sess.ConvertMime = False
	Set doc = db.CreateDocument
	doc.Subject = subject
	Set body = doc.CreateMIMEEntity("Body")
	Set stream = sess.CreateStream
	Call stream.WriteText(html)
	Call body.SetContentFromText(stream, {text/html; charset="iso-8859-1"}, ENC_QUOTED_PRINTABLE)
	Call doc.CloseMIMEEntities(True, "Body")
	sess.ConvertMime = True
	
	' open the new memo
	Dim ws As New NotesUIWorkspace
	Call ws.EditDocument(True, doc)
	
End Function

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Bill-Hanson
Bill-Hanson
Flag of United States of America 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
SOLUTION
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
Avatar of KTTKTT

ASKER

AWESOME ! you're the best ! works great ! thank you so much for your generosity ! I will study the code !

I placed the above in the email button:

Sub Click(Source As Button)
      Dim memo As NotesUIDocument
      Set memo = ComposeMimeMemoEx("test", "This is a <b>test</b>!<br><a href = 'http://www.google.com'>Google</a>")
      Call memo.FieldSetText("EnterSendTo", "kimthom@us.ibm.com")
End Sub
Avatar of KTTKTT

ASKER

oh forgot to mention that I received the error msg.:  "ComposeMimeMemoEx: Public not allowed in this module"  -
I removed "Public" from Public Function ComposeMimeMemoEx(Byval subject As String, Byval html As String) As NotesUIDocument"

Not sure what the difference is:  Public Function vs. Function  - will look it up
Public / Private

These are called 'access specifiers' and are used to define where a function may be used.

Public - The function may be called from any context (action, agent, etc).

Private - The function may be called only by other functions in the current module.

For example, assume we have a LotusScript library named "Common Functions".  In that library are several functions that we want to use in several places (like ComposeMimeMemoEx).  Also in that library are a few "helper functions" that are used only by other functions inside the "Common Functions" library.  Assume that these "helper functions" would fail if they were called directly from an action or agent (maybe the "helper function" relies on a temp doc that is first created by one of the main functions in the library).  You could just remember to never use these "helper functions" outside the library, but there's a better way.  By including the Private keyword, you make the "helper function" invisible to modules outside the library, thus preventing accidental use.

Now that we know this, the error that you mentioned above makes sense.  Code that is stored inside of a form cannot be called from outside of the form, so the Public keyword is not valid.  The code could never be Public.

BTW: You really should place these functions inside of a shared library.  That way, you can reuse them in all of your apps.  Let me know if you want help setting one up.
Avatar of KTTKTT

ASKER

Hi Bill,

that would be great. thx.  The emal text for the Set memo = ComposeMimeMemoEx works great until I add a lot of text - get error msg. "Wrong number of arguments for ComposeMimeMemoEx"  I tried placing quotes around each line and adding the continuation line (&_), but that didn't work.  Let me know if this needs to be a separate question, because I also need to add an image to the memo.  The script is in a notes email button for now.
Avatar of KTTKTT

ASKER

I was able to get the long text to work - removed spaces after &_ each continuation line
Avatar of KTTKTT

ASKER

Bill,

Do you know if there is a reason why this won't work on a Notes 7 client.  I have Notes 8 and it works great on Notes 8 client.  A user still on Notes 7 gets error msg. "Object Variable not set" at this line:
Call memo.FieldSetText("EnterSendTo", "user notes id here")

thanks
There's no reason that I can think of.  The client version should not matter.  I'm using R7 myself, and that is what I tested this script on.

The only object variable on that line is "memo".  Take a look at your code to make sure that you have not changed the variable name to something else.  Make sure that your ComposeMimeMemoEx function is returning the NotesUIDocument that was created by the function and assigning it to the correct variable.

Also, if you still need to add images, let me know.  I have examples, but have not had time to respond until now.
Avatar of KTTKTT

ASKER

I didn't change your code above, but...added this additional email confirmation note code that works on notes 8 but gives object variable not set on notes 7 :

'1st email note automatically sent to inform you that a user clicked this button
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim doc As NotesDocument
      Set db = session.CurrentDatabase
      Set doc = New NotesDocument( db )
      doc.Form = "Memo"
      doc.SendTo = "xxx.......com"    'CHANGE SEND TO HERE
      doc.Subject = "confirmation note"   'CHANGE SUBJECT LINE HERE
      doc.body = "I clicked on this button - will attend event' "   'CHANGE BODY TEXT HERE
      Call doc.Send( False )
      'end of 1st email note

------------
Also, I'm using an email button that will be forwarded via Notes email to others to click button to compose memo - I placed all code in the Click object - now I'm moving this line to Initialize to see what happens w/Notes 7:  
Dim memo As NotesUIDocument
I'm a little confused.  I don't see any reference to memo in the code above.  Is this a different error?

Also, not sure why you're declaring memo in Initialize.
Avatar of KTTKTT

ASKER

I got the image to work using this, but since i have so much text i probably should be using better html and the paragraph tag <p>:

"<br><br><font size=4><b>Lets build a smarter planet.</font></b>" &_
      "<br><br><font size=4><b><a href ='http://www.google.com'>Click here for information.</a>"&_
      "<br><br><img src='http://www.xyz.com/images/pic05075.jpg'/>"&_
Now I'm really confused.  Please post all of your code and use the "Attach Code Snippet" so that it will not be interpreted as HTML.
Avatar of KTTKTT

ASKER

my apologies. Here is code.  thanks
Sub Click(Source As Button)
	
	'1st email note automatically sent to inform you that a user clicked this button
	Dim session As New NotesSession
	Dim db As NotesDatabase
	Dim doc As NotesDocument
	Set db = session.CurrentDatabase
	Set doc = New NotesDocument( db )
	doc.Form = "Memo"
	doc.SendTo = "xxx.xxx.com"    'CHANGE SEND TO HERE
	doc.Subject = "confirmation note - I will attend this function"  'CHANGE SUBJECT LINE HERE
	doc.body = "I clicked on this button and plan to attend....' "   'CHANGE BODY TEXT HERE
	Call doc.Send( False )
	'end of 1st email note
	
	'-----------------------------------
	
	'2nd Email note - Allow user to Compose Memo 
	Dim memo As NotesUIDocument
	
	' the first line BEFORE THE COMMA, is the Subject text .  Body text follows> Be sure there are no spaces after each continuation line of text: &_.   
'Also notice that the url and image links are in 'single' quotes
	' Each line of text/html should be enclosed in double quotes
	' Do not remove the apostrophe ) from the last line of text which closes the entire text string
	
	Set memo = ComposeMimeMemoEx("subject text here", _
	"<font size=6><b>This is my body text"&_
	"</font></b><br><br>More Body Text" &_
	"New text, new text.....:<br><br><font size=4><b>Bold text, font 4 here.</font></b>and more text " &_
	"<br><br><font size=4><b><a href ='http://www.google.com'>Click here for more information.</a>"&_
	"<br><br><img src='http://www.xxx.com/images/pic050555.jpg'/>"&_
	"<br><br><font size = 1>This information ...All rights reserved.)"   )
	
	Call memo.FieldSetText("EnterSendTo", "ktt@xxx.com")	  'Add intranet id in the quotes for the SendTo field 	
End Sub
 
 
 
Function ComposeMimeMemoEx(Byval subject As String, Byval html As String) As NotesUIDocument
	
	Dim ws As New NotesUIWorkspace
	Dim sess As New NotesSession
	Dim db As New NotesDatabase("", "")
	Dim uiTemp As NotesUIDocument, memo As NotesUiDocument
	Dim docTemp As NotesDocument
	Dim body As NotesMimeEntity
	Dim stream As NotesStream
	On Error Goto CATCH
	
        ' create MIME using a temp document
	Call db.OpenMail
	sess.ConvertMime = False
	Set docTemp = db.CreateDocument
	Set body = docTemp.CreateMIMEEntity("Body")
	Set stream = sess.CreateStream
	Call stream.WriteText(html)
	Call body.SetContentFromText(stream, {text/html; charset="iso-8859-1"}, ENC_QUOTED_PRINTABLE)
	Call docTemp.CloseMIMEEntities(True, "Body")
	sess.ConvertMime = True
	Call docTemp.Save(True, False)
	
        ' copy generated HTML to the clipboard
	Set uiTemp = ws.EditDocument(True, docTemp)
	Call uiTemp.GotoField("Body")
	Call uiTemp.SelectAll
	Call uiTemp.Copy
	uiTemp.Document.SaveOptions = "0"
	uiTemp.Document.MailOptions = "0"
	Call uiTemp.Close
	Call docTemp.Remove(True)
	Set docTemp = Nothing
	
        ' compose the new memo
	Set memo = ws.ComposeDocument(db.Server, db.Filepath, "Memo")
	Call memo.FieldSetText("Subject", subject)
	Call memo.GotoField("Body")
	Call memo.Paste
	
	Set ComposeMimeMemoEx = memo
	
	Exit Function
	
CATCH:
	If (Not docTemp Is Nothing) Then If (Not docTemp.IsNewNote) Then Call docTemp.Remove(True)
	Exit Function
	
End Function

Open in new window

Thanks.

I don't see anything wrong with the LotusScript here.  I do see a few HTML errors, but that should not cause an object variable error.

I recommend that you store the HTML in a separate variable for clarity, and use the pipe (|) char instead of double-quotes to surround the string.  This does a couple of things for you:  1) you don't need the line continuation operators to span multiple lines, 2) you can include quotes in the HTML, 3) it's easier to read.

Here's a short example with the HTML errors fixed for you :)
        Dim html as String
 
        html = |<font size=6><b>This is my body text</b></font><br><br>
More Body Text New text, new text.....:<br><br>
<font size=4><b>Bold text, font 4 here.</b></font> and more text<br><br>
<font size=4><b><a href ='http://www.google.com'>Click here for more information.</a></b></font><br><br>
<img src='http://www.xxx.com/images/pic050555.jpg'/><br><br>
<font size = 1>This information ...All rights reserved.</font>|
 
        Set memo = ComposeMimeMemoEx(html)

Open in new window

Avatar of KTTKTT

ASKER

thanks Bill.

Receiving following error for:  Set memo = ComposeMimeMemoEx ( html )
"missing argument for: COMPOSEMIMEMEMOEX"



Dim memo As NotesUIDocument
	
Dim html As String
 
html = | <font size = 6><B>This is my body text</b></font><br><br>
More Body text...:<br><br>
<font size = 4><b>Bold text here, font size 4
</b></font> and more text <br><br> <font size = 4><b><a href = 'http:/www.google.com'>Click here for information.</a></b></font><br>
<img src = 'http://www.xxx.com/images/pic05555.jpg' /><br><br>
<font size = 1>This information...all rightrs reserved.</font>  |
	
Set memo = ComposeMimeMemoEx( html )
	
Call memo.FieldSetText("EnterSendTo", "")

Open in new window

Sorry, I missed the subject param...
Dim memo As NotesUIDocument
        
Dim html As String
 
html = | <font size = 6><B>This is my body text</b></font><br><br>
More Body text...:<br><br>
<font size = 4><b>Bold text here, font size 4
</b></font> and more text <br><br> <font size = 4><b><a href = 'http:/www.google.com'>Click here for information.</a></b></font><br>
<img src = 'http://www.xxx.com/images/pic05555.jpg' /><br><br>
<font size = 1>This information...all rightrs reserved.</font>  |
        
Set memo = ComposeMimeMemoEx( "subject text here", html )
        
Call memo.FieldSetText("EnterSendTo", "user@domain.com")

Open in new window

Avatar of KTTKTT

ASKER

Thanks again Bill.  Working great for Notes 8 clients.  I know that you mentioned it works for you on Notes 7.

I'm investigating reason for Notes 7 Object Variable not set - not sure if it's workstation configuration/settings or not.